ClearCode

ImageOps

May 18th, 2022
1,946
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. from PIL import Image, ImageOps
  2.  
  3. # image import
  4. image = Image.open('picture.jpg')
  5.  
  6. # color changes
  7. image_contrast = ImageOps.autocontrast(image = image, cutoff = 5)
  8. image_inverted = ImageOps.invert(image)
  9. image_solarize = ImageOps.solarize(image = image, threshold = 100)
  10. image_posterize = ImageOps.posterize(image = image, bits = 1)
  11. image_grayscale = ImageOps.grayscale(image = image)
  12. image_equalized = ImageOps.equalize(image = image)
  13. image_colorize = ImageOps.colorize(image = image.convert('L'), black = 'blue', white = 'red')
  14.  
  15. # dimension changes
  16. image_mirror = ImageOps.mirror(image)
  17. image_flip = ImageOps.flip(image)
  18. image_scale = ImageOps.scale(image = image, factor = 0.4)
  19. image_contain = ImageOps.contain(image = image, size = (500,200))
  20.  
  21. # Adding and removing
  22. image_border = ImageOps.expand(image = image, border = 100, fill = (255,255,0))
  23. image_padded = ImageOps.pad(image = image, size = (2500,1600))
  24. image_fit = ImageOps.fit(image = image, size = (500,300))
  25. image_crop = ImageOps.crop(image = image, border = 400)
  26.  
  27. image_flip.show()
Advertisement
Add Comment
Please, Sign In to add comment