Created
July 1, 2011 22:42
-
-
Save ivanyv/1059545 to your computer and use it in GitHub Desktop.
Make chunky pixels the brute force way
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'chunky_png' | |
orig = ChunkyPNG::Image.from_file('input.png') | |
rows = (orig.width / 10.0).ceil | |
cols = (orig.height / 10.0).ceil | |
canvas = ChunkyPNG::Canvas.new(rows * 10, cols * 10).replace(orig) | |
(0...rows).each do |row| | |
x = row * 10 | |
(0...cols).each do |col| | |
y = col * 10 | |
chunk = canvas.crop(x, y, 10, 10).resample(100, 100).crop(45, 45, 10, 10) | |
canvas.replace!(chunk, x, y) | |
end | |
end | |
canvas.crop(0, 0, orig.width, orig.height).save('output.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment