Skip to content

Instantly share code, notes, and snippets.

@averyvery
Created February 20, 2013 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save averyvery/4999932 to your computer and use it in GitHub Desktop.
Save averyvery/4999932 to your computer and use it in GitHub Desktop.
Save resized copies of retina images at regular size.
require 'rmagick'
source = ARGV[0]
Dir.glob('images/' + source + '/*.*').each do |retina_path|
mobile_path = retina_path.sub(/retina/, 'normal')
retina_file = File.new(retina_path)
mobile_file = File.new(mobile_path) if File.exist?(mobile_path)
if !File.exist?(mobile_path) || retina_file.mtime > mobile_file.mtime
puts ' Retina image has changed! Shrinking: ' + retina_path
GC.start
image = Magick::Image::read(retina_path).first
image.resize!(image.columns / 2, image.rows / 2, Magick::GaussianFilter, 0.2)
image.write mobile_path
image.destroy!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment