Skip to content

Instantly share code, notes, and snippets.

@dirceu-jr
Created February 19, 2009 18:28
Show Gist options
  • Save dirceu-jr/67042 to your computer and use it in GitHub Desktop.
Save dirceu-jr/67042 to your computer and use it in GitHub Desktop.
require 'RMagick'
include Magick
from_img = File.join(File.expand_path(File.dirname(__FILE__)), 'dirs_vector2.png')
to_js = File.join(File.expand_path(File.dirname(__FILE__)), '..', 'imgs', 'dirs_vector.js')
dirs = ImageList.new(from_img)
bitmap = "var colors = ["
dirs.each_pixel do |i|
r = i[0].red
g = i[0].green
b = i[0].blue
bitmap << "'#{r},#{g},#{b}',"
end
bitmap << "]"
file = File.open(to_js, 'w')
file.puts(bitmap)
file.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment