summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbuild.rb33
1 files changed, 19 insertions, 14 deletions
diff --git a/build.rb b/build.rb
index a617fc0..1805a47 100755
--- a/build.rb
+++ b/build.rb
@@ -7,10 +7,10 @@ require 'mini_magick'
require 'fileutils'
require 'erb'
-def copyimage(path, file, target)
+def copyimage(path, file, target, extension)
hash = Digest::MD5.file(file).hexdigest
hash = Digest::MD5.hexdigest(hash.to_s + target)
- filename = "#{hash}.jpg"
+ filename = "#{hash}.#{extension}"
dest = File.join(path, filename)
if File.exist?(dest)
@@ -22,6 +22,7 @@ def copyimage(path, file, target)
# Resize image and write it to destination
image = MiniMagick::Image.open(file)
image.resize(target)
+ image.format(extension)
image.write(dest)
return filename
@@ -64,11 +65,15 @@ OptionParser.new do |opts|
opts.on("-b", "--linkbase URL", "Add links to images, with URL as base") do |url|
options[:base] = url
end
+ opts.on("-e", "--extension EXT", "Image extension to use with imagemagick") do |ext|
+ options[:extension] = ext
+ end
end.parse!
options[:path] = "build" unless options[:path]
options[:size] = "1920x1080" unless options[:size]
options[:clean] = false unless options[:clean]
+options[:extension] = "jpg" unless options[:extension]
puts options
# Create build dir
@@ -84,7 +89,7 @@ defs["groups"].each do |value|
# For each image inside group
forImgs(value["imgs"]) do |img|
puts "Converting file #{img}"
- dest = copyimage(options[:path], img, options[:size])
+ dest = copyimage(options[:path], img, options[:size], options[:extension])
files[img] = dest
end
@@ -95,6 +100,17 @@ puts files
template = File.read("index.tmpl")
template = template.split("%BODY%")
+# Cleanup old files
+if options[:clean]
+ Dir.glob(File.join(options[:path], "*")) do |file|
+ hash = File.basename(file)
+ if !files.values.include? hash
+ puts "Cleaning #{hash}"
+ File.delete(file)
+ end
+ end
+end
+
File.open(File.join(options[:path], "index.html"), "w") do |file|
# Print preample
file.write(template[0])
@@ -127,14 +143,3 @@ File.open(File.join(options[:path], "index.html"), "w") do |file|
# Print postampleee?
file.write(template[1])
end
-
-# Cleanup old files
-if options[:clean]
- Dir.glob(File.join(options[:path], "*.jpg")) do |file|
- hash = File.basename(file)
- if !files.values.include? hash
- puts "Cleaning #{hash}"
- File.delete(file)
- end
- end
-end