Jump to content
Wikibooks The Free Textbook Project

Python Imaging Library/File IO

From Wikibooks, open books for an open world

File operations in PIL are very simple, and reflect normal Python methods.

This page or section is an undeveloped draft or outline.
You can help to develop the work, or you can ask for assistance in the project room.

open

[edit | edit source ]
importImage
img = Image.open(filepath)

load

[edit | edit source ]
fromPILimport Image
img = Image.open("path/to/image.ext")
pixels = img.load() # Load the pixels of the image into a matrix

show

[edit | edit source ]

Displays a copy of the specified image in a window.

fromPILimport Image
img = Image.open("path/to/image.ext")
img.show() # Shows the image in a new window

save

[edit | edit source ]
importImage
img = Image.open(filepath)
img.save("example.png")
#img.save(outfile, options...)
#img.save(outfile, format, options...)

AltStyle によって変換されたページ (->オリジナル) /