Commit 9050e028 authored by Martin Fischbach's avatar Martin Fischbach
Browse files

revised image resizing

parent ffd28675
Gem::Specification.new do |spec|
spec.name = "jekyll-img-srcset"
spec.version = "0.2.51"
spec.version = "0.3.0"
spec.authors = ["Jan-Philipp Stauffert"]
spec.email = ["jan-philipp.stauffert@uni-wuerzburg.de"]
......
......@@ -7,6 +7,8 @@ class WatchAndResize
images = Dir.glob("./assets/images/**/*.{jpg,JPG,jpeg,JPEG,png,PNG}")
start = Time.now
Parallel.each(images) do |source_path|
destinations = generate_destinations(source_path.gsub("assets/images/", ""), [320, 640, 844, 1208, 1688], "./public", "./assets/images")
min_width_path = destinations[0][1]
......@@ -19,7 +21,9 @@ class WatchAndResize
#STDOUT.flush
end
puts "YOU ARE AWESOME!!"
delta = Time.now - start
puts "Checked and resized './assets/images' if necessary in #{delta} seconds."
STDOUT.flush
#Filewatcher.new('/website/').watch do |filename, event|
# puts "#{filename} #{event}"
......@@ -69,7 +73,7 @@ end
# the generated widths and the original iamge width
def resize_image(url, widths, dest, base_image_path) #, cache
src_path = File.join(base_image_path, url)
puts "resizing: #{src_path}"
puts "Resizing: #{src_path}"
STDOUT.flush
#src_mtime = File.new(src_path).mtime
......@@ -94,8 +98,20 @@ def resize_image(url, widths, dest, base_image_path) #, cache
image = MiniMagick::Image.open(src_path)
w = image.dimensions[0]
aspect = image.dimensions[1].to_f / w
aspect = image.dimensions[1].to_f / w
#https://www.imagemagick.org/discourse-server/viewtopic.php?t=20784
#https://github.com/minimagick/minimagick#metal
#https://www.rubydoc.info/github/minimagick/minimagick/MiniMagick/Tool/Convert
#https://www.rubydoc.info/github/minimagick/minimagick/MiniMagick%2FTool:%3C%3C
#
### Idea
#convert = MiniMagick::Tool::Convert.new
#convert << "path/to/image.jpg"
#for
# convert << "\( -clone 0 -resize #{width}x#{width*aspect} -write #{target} \)"
#end
#convert.call
for jobInfo in width_to_create do
width = jobInfo[0]
target = jobInfo[1]
......@@ -103,12 +119,13 @@ def resize_image(url, widths, dest, base_image_path) #, cache
FileUtils.mkdir_p File.dirname(target)
end
if width < w
#image = MiniMagick::Image.open(@image.path)
image.resize "#{width}x#{width*aspect}"
image.write target
cloned_image = MiniMagick::Image.open(src_path)
cloned_image.resize "#{width}x#{width*aspect}"
cloned_image.write target
else
FileUtils.copy_file(src_path, target)
end
end
puts "finished: #{src_path}"
puts "Finished resizing: #{src_path}"
STDOUT.flush
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment