1
0
mirror of https://github.com/danbee/danbarber.me synced 2025-03-04 08:59:10 +00:00
danbarber.me/_plugins/minimagick.rb

42 lines
844 B
Ruby

require "mini_magick"
module Jekyll
module MiniMagick
def magick(image_path, options)
filename, ext = image_path.split("/").last.split(".")
dest_path = image_path.
split("/")[0..-2].
prepend("assets").
join("/")
options.each do |command, arg|
filename += "_#{command}#{arg}"
end
write_path = "#{dest_path}/#{filename}.#{ext}"
if File.exists?("_site/#{write_path}")
return write_path
end
image = ::MiniMagick::Image.open("_pictures/#{image_path}")
image.combine_options do |i|
options.each do |command, arg|
i.send command, arg
end
i.strip
end
puts write_path
image.write "_site/#{write_path}"
write_path
end
end
end
Liquid::Template.register_filter(Jekyll::MiniMagick)