Skip to content

Instantly share code, notes, and snippets.

@tobynet
Created October 16, 2010 10:38
Show Gist options
  • Select an option

  • Save tobynet/629658 to your computer and use it in GitHub Desktop.

Select an option

Save tobynet/629658 to your computer and use it in GitHub Desktop.
gameboynize test script
#!ruby -Ku
# gameboynize test script
#
# Original author: http://twitter.com/toby_net
#
# License: WTFPL - Do What The Fuck You Want To Public License Version 2
# official: http://sam.zoy.org/wtfpl/
# eng: http://en.wikipedia.org/wiki/WTFPL
# jpn: http://ja.wikipedia.org/wiki/WTFPL
require 'pp'
require 'rubygems'
begin
require 'faster_require'
rescue LoadError
end
require 'RMagick'
def assets_filename(filename)
# base dir on "../assets" or same as source dir
assets_dir = File.join(File.dirname(__FILE__), "../assets")
dir = File.exists?(assets_dir) ? assets_dir : File.dirname(__FILE__)
return File.join(dir, filename)
end
def downlaod_and_save(filename, uri)
# fucking so long code for downloading image and saving to file!!! must be golf or die!!!!!!
full_filename = assets_filename(filename)
unless File.exists? full_filename
require 'open-uri'
print "downloading #{filename}..."
File.open(full_filename, "wb"){|x| x.write(open(uri).read) }
puts "damn!!"
end
return full_filename
end
def load_image(*options)
return Magick::Image.read(downlaod_and_save(*options)).first
end
# loading free oquno and other assets
image = load_image("oquno-c.png", "http://gyazo.com/0741e4771caac3849f4e4d3b418591d9.png")
gblike_image = load_image("gb_like.png", "http://gyazo.com/449d1278d871863da8c99693d360f535.png")
pp image
pp gblike_image
# syukusyo!!
image.resize_to_fit!(width_or_height_pixels = 48)
# gensyoku!!
image = image.quantize(color_num = 5, Magick::GRAYColorspace, Magick::NoDitherMethod)
# colored like a gameboy
image.remap(gblike_image, Magick::NoDitherMethod)
#image.affinity(gblike_image)
pp image
# kakudai!!
image.scale!(scaling_factor = 8)
#image.colorize!(90, 84, 65, "blue")
image.write assets_filename("out.png")
pp image
puts "DONE!!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment