HOME/Articles/

pil example jpg2png2invert (snippet)

Article Outline

Python pil example 'jpg2png2invert'

Modules used in program:

  • import PIL.ImageOps

python jpg2png2invert

Python pil example: jpg2png2invert

from PIL import Image
import PIL.ImageOps
#Using PIL/pillow (install with 'pip3 install pillow' ) 
name = 'RPS-g2.jpg'
outname = 'RPS-g2.png' #png extension
im = Image.open(name)
inv = PIL.ImageOps.invert(im) #invert opperation
inv.save(outname)