-
-
Save jmorton/1e7291f5337fc18be247 to your computer and use it in GitHub Desktop.
Chunky
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 'chunky_png' | |
module Pixelize | |
# Replace chunks of an image with a single color. | |
# | |
# @param size Number of pixels to consolidate | |
# | |
def pixelize!(size) | |
# Step over each chunk horizontally and vertically, being careful | |
# not to exceed the boundaries (hence subtracting one). | |
0.step(self.width-1, size) do |x1| | |
x2 = x1+size-1 | |
0.step(self.height-1, size) do |y1| | |
y2 = y1+size-1 | |
rect(x1, y1, x2, y2, ChunkyPNG::Color::TRANSPARENT, self[x1,y1]) | |
end | |
end | |
end | |
end | |
class ChunkyPNG::Image | |
include Pixelize | |
end | |
img = ChunkyPNG::Image.from_file('output.png') | |
img.pixelize!(10) | |
img.save('chunky3.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment