Ce projet essai, en partant d'une IMAGESOURCE de : - appliquer des effets à l'image - la redimmensionner - changer son mode de couleur - la HAACHEER...
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pixelate.py 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from PIL import Image
  2. '''
  3. backgroundColor = (0,)*3
  4. '''
  5. pixelSize = 8
  6. image = Image.open('pixelate_input.png')
  7. image = image.resize((image.size[0]/pixelSize, image.size[1]/pixelSize), Image.NEAREST)
  8. image = image.resize((image.size[0]*pixelSize, image.size[1]*pixelSize), Image.NEAREST)
  9. pixel = image.load()
  10. '''
  11. for i in range(0,image.size[0],pixelSize):
  12. for j in range(0,image.size[1],pixelSize):
  13. for r in range(pixelSize):
  14. pixel[i+r,j] = backgroundColor
  15. pixel[i,j+r] = backgroundColor
  16. '''
  17. image.save('pixelate_output.png')
  18. '''
  19. load
  20. im.load()
  21. Allocates storage for the image and loads it from the file (or from the source, for lazy operations). In normal cases, you don’t need to call this method, since the Image class automatically loads an opened image when it is accessed for the first time.
  22. (New in 1.1.6) In 1.1.6 and later, load returns a pixel access object that can be used to read and modify pixels. The access object behaves like a 2-dimensional array, so you can do:
  23. pix = im.load()
  24. print pix[x, y]
  25. pix[x, y] = value
  26. Access via this object is a lot faster than getpixel and putpixel.
  27. '''