class - pillow

介紹

 

 


# return 的 im 是 "Image object"

    from PIL import Image
    im = Image.open("lime.jpg")

* If the file cannot be opened, an IOError exception is raised.

 

# instance attributes

from __future__ import print_function
print(im.format, im.size, im.mode)

PPM (512, 512) RGB

# show

# window: 相片檢視器
# linux: xv utility to display the image

im.show()

 

# save() - JPEG

# infile, outfile 是檔名
# Unless you specify the format, the library uses the filename extension to discover which file storage format to use.

from PIL import Image
try:
    Image.open(infile).save(outfile)
except IOError:
    print("cannot convert", infile)

DOC

https://pillow.readthedocs.org/handbook/tutorial.html

 

Creative Commons license icon Creative Commons license icon