Skip to content

Instantly share code, notes, and snippets.

@itochan
Created October 11, 2013 14:49
Show Gist options
  • Save itochan/6936006 to your computer and use it in GitHub Desktop.
Save itochan/6936006 to your computer and use it in GitHub Desktop.
require 'rmagick'
dir = "/Users/itochan/Downloads/favicon"
# csv = CSV.read("#{dir}/../top-1m.csv")
pixels = []
64.times do |i|
pixels[i] = []
end
colors = []
Dir::glob("#{dir}/icons/*").each do |file|
puts file
img = Magick::Image.read(file).last
img.resize!(64, 64) if img.columns != 64 && img.rows != 64
64.times do |i|
colors[file][i] = []
end
img.each_pixel do |pixel, x, y|
current = img.pixel_color(x, y)
pixel = pixels[x][y]
if pixel
red = current.red
green = current.green
blue = current.blue
pixels[x][y] = Magick::Pixel.new(
(red + pixel.red) / 2,
(green + pixel.green) / 2,
(blue + pixel.blue) / 2)
else
pixels[x][y] = current
end
end
end
output_img = Magick::Image.new(64, 64)
output_img.each_pixel do |pixel, x, y|
pixel = pixels[x][y]
color = Magick::Pixel.new(
pixel.red,
pixel.green,
pixel.blue
)
output_img.pixel_color(x, y, color)
end
output_img.write("#{dir}/output.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment