ImageOps
Module#
The ImageOps
module contains a number of ‘ready-made’ image
processing operations. This module is somewhat experimental, and most operators
only work on L and RGB images.
New in version 1.1.3.
Resize relative to a given size#
from PIL import Image, ImageOps
size = (100, 150)
with Image.open("Tests/images/hopper.png") as im:
ImageOps.contain(im, size).save("imageops_contain.png")
ImageOps.cover(im, size).save("imageops_cover.png")
ImageOps.fit(im, size).save("imageops_fit.png")
ImageOps.pad(im, size, color="#f00").save("imageops_pad.png")
# thumbnail() can also be used,
# but will modify the image object in place
im.thumbnail(size)
im.save("imageops_thumbnail.png")
|
|
|
|
|
|
---|---|---|---|---|---|
Given size |
|
|
|
|
|
Resulting image |
![]() |
![]() |
![]() |
![]() |
![]() |
Resulting size |
|
|
|
|
|