From 40d11fa9ac79cf2ddd16770cd9f27022f8a34fa5 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 28 Sep 2023 08:27:56 +1000 Subject: [PATCH] Added demonstration images to tutorial --- docs/handbook/tutorial.rst | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/docs/handbook/tutorial.rst b/docs/handbook/tutorial.rst index 50133f15ec2..cef2c62c2d4 100644 --- a/docs/handbook/tutorial.rst +++ b/docs/handbook/tutorial.rst @@ -268,6 +268,35 @@ true, to provide for the same changes to the image's size. A more general form of image transformations can be carried out via the :py:meth:`~PIL.Image.Image.transform` method. +Relative resizing +^^^^^^^^^^^^^^^^^ + +Instead of calculating the size of the new image when resizing, you can also +choose to 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_pad.png") + ++------+-------------------------------------------+--------------------------------------------+------------------------------------------+----------------------------------------+----------------------------------------+ +| | :py:meth:`~PIL.Image.Image.thumbnail` | :py:meth:`~PIL.ImageOps.contain` | :py:meth:`~PIL.ImageOps.cover` | :py:meth:`~PIL.ImageOps.fit` | :py:meth:`~PIL.ImageOps.pad` | ++======+===========================================+============================================+==========================================+========================================+========================================+ +|Size | (100, 100) | (100, 100) | (150, 150) | (150, 100) | (150, 100) | ++------+-------------------------------------------+--------------------------------------------+------------------------------------------+----------------------------------------+----------------------------------------+ +|Image | .. image:: ../example/image_thumbnail.png | .. image:: ../example/imageops_contain.png | .. image:: ../example/imageops_cover.png | .. image:: ../example/imageops_fit.png | .. image:: ../example/imageops_pad.png | ++------+-------------------------------------------+--------------------------------------------+------------------------------------------+----------------------------------------+----------------------------------------+ + .. _color-transforms: Color transforms