Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Pillow Tutorial

Pillow Tutorial

Pillow is the primary library for image processing in Python.

Pillow is a friendly fork of the Python Imaging Library (PIL).

Since the original PIL is no longer maintained, Pillow has taken over its role and continues active development.

Pillow provides extensive file format support, efficient internal representation, and powerful image processing capabilities.


Who should read this tutorial?

This tutorial is suitable for developers with a Python foundation.

If you are not yet familiar with Python, you can first learn Python Tutorial。


Main Features


Comparison with Other Libraries


First Pillow Example

After installing Pillow, you still use import PIL or from PIL import ... to import modules.

The following example shows the basic information of an image:

Example

from

PIL

import

Image

Open an image

img

=

Image.

open

(

"example.jpeg"

)

Displaying an Image

img.

show

(

)

Get image information

print

(

"Image format:"

,

img.

format

)

 

JPEG, PNG, etc.

print

(

"Image size:"

,

img.

size

)

   

(width, height)

print

(

"Image mode:"

,

img.

mode

)

 

RGB, L, etc.

Save in PNG format

img.

save

(

"example.png"

)

Running result:

图片格式: JPEG
图片大小: (987, 987)
图片模式: RGB

After running, the image will also be saved as example.png.


Related content