crzcas

pixelation

Jan 2nd, 2021 (edited)
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. from PIL import Image    #Import the Image module from the PIL library
  2.  
  3. image = Image.open("houses.png")    #Create a path to the image file
  4.  
  5. rgb_image = image.convert('RGB')    #Convert the image to RGB
  6.  
  7. width, height = image.size     #Assign the image's width and height to variables
  8.  
  9. output_image = Image.new('RGB', (width,height))     #Create a grid for the output image
  10.  
  11. out = Image.new('RGB', (width,height))
  12.  
  13. pixelAmount = 8
  14.  
  15.  
  16. for row in range(0, height - pixelAmount, pixelAmount):
  17.     for col in range(0, width - pixelAmount, pixelAmount):
  18.         r, g, b = rgb_image.getpixel((col, row))
  19.  
  20.  
  21.         for o in range(row, row + pixelAmount):
  22.             for p in range(col, col + pixelAmount):
  23.                 out.putpixel((p,o), (r,g,b))  
  24.  
  25. out.save("pixelation_image_out.png")
  26.  
  27. out.show()
Advertisement
Add Comment
Please, Sign In to add comment