Scale pixel art images to 200%
Usage: ruby 2x.rb [-f] image.png another_image.png
https://gist.github.com/raine/9390642
#!/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
Written by Raine Virta
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#