Skip to content

Instantly share code, notes, and snippets.

@rempargo
Forked from jeffkreeftmeijer/bassie.png
Last active August 31, 2015 13:05
Show Gist options
  • Save rempargo/e620cefc02fcfac09637 to your computer and use it in GitHub Desktop.
Save rempargo/e620cefc02fcfac09637 to your computer and use it in GitHub Desktop.
ChunkyPNG nearest-neighbor resize
require 'chunky_png'
image = ChunkyPNG::Image.from_file('bassie.png')
[2,0.5].each do |scale|
resized_image = ChunkyPNG::Image.new((image.width * scale).round, (image.height * scale).round)
resized_image.pixels.map!.with_index do |pixel, index|
x, y = index % resized_image.width, (index / resized_image.width).floor
image[x / scale, y / scale]
end
resized_image.save("bassie_resized_#{scale}.png")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment