-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmakepage.rb
executable file
·45 lines (35 loc) · 1.03 KB
/
makepage.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/ruby
require 'fileutils'
MAX_PHOTOS = 9
# potentially get photos from a specified directory
input_photos_dir = 'input-photos'
if ARGV.length > 0
input_photos_dir = ARGV[0]
end
puts "Reading images from #{input_photos_dir}"
# get a list of the photos to use
photos = Dir.glob("#{input_photos_dir}/*.jpg", File::FNM_CASEFOLD)
# randomise photo input order
photos.shuffle!
pages = Dir.entries('pages')
new_page = "pages/#{pages.length - 1}"
if File.exist?(new_page)
abort("Error: #{new_page} directory already exists!")
end
# make a directory for the page, and include all the templates
Dir.mkdir new_page
FileUtils.cp_r Dir.glob('templates/*.svg'), new_page
counter = 0
while counter < MAX_PHOTOS && rand = photos.pop
puts "Using random image: #{rand}"
if File.file? rand
counter += 1
FileUtils.cp rand, "#{new_page}/photo#{counter}.jpg"
else
puts " Skipping, isn't a file!"
end
end
# generate png exports for ease of review
Dir.glob("#{new_page}/*.svg").each do |x|
system "inkscape #{x} -e #{x}.png"
end