- 
      
- 
        Save rempargo/e620cefc02fcfac09637 to your computer and use it in GitHub Desktop. 
    ChunkyPNG nearest-neighbor resize
  
        
        
        
        
  
    
      This file contains hidden or 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' | |
| 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
  
            

