Skip to content

Instantly share code, notes, and snippets.

@srgtuszy
Created November 16, 2012 12:35
Show Gist options
  • Save srgtuszy/4086991 to your computer and use it in GitHub Desktop.
Save srgtuszy/4086991 to your computer and use it in GitHub Desktop.
A script for resizing retina images for regular screens
#! /usr/bin/env ruby
require 'RMagick'
def resize_image (image_path, write_path)
image = Magick::Image.read(image_path).first
new_image = image.scale(0.5)
puts "Writing image #{write_path}..."
new_image.write(write_path)
end
directory_path = ARGV[0]
dir_contents = Dir.entries(directory_path)
dir_contents.each do |f|
next if f.include?("@2x") == false
puts "Resizing #{f}..."
new_name = f.sub("@2x", "")
image_path = "#{directory_path}#{f}"
write_path = "#{directory_path}#{new_name}"
resize_image(image_path, write_path)
end
puts "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment