Skip to content

Instantly share code, notes, and snippets.

@raine
Last active August 29, 2015 13:57
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 raine/9390642 to your computer and use it in GitHub Desktop.
Save raine/9390642 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# [sudo] gem install rmagick
require 'rmagick'
def prepend_ext(path, with)
with_ext = File.basename path
ext = File.extname path
no_ext = File.basename path, ext
path.sub with_ext, "#{no_ext}#{with}#{ext}"
end
if ARGV.first === '-f'
ARGV.shift
force = true
end
if ARGV.empty?
puts "Usage: #{__FILE__} [-f] FILE(S)"
exit
end
ARGV.each do |path|
img = Magick::Image.read(path).first
width = img.columns
height = img.rows
dst = (if force then path else "#{prepend_ext(path, '_2x')}" end)
img.resize!(width * 2, height * 2, Magick::BoxFilter, 0)
img.write dst
puts "Wrote to #{dst}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment