Back to articles
How to Resize an Image in Python Using PIL (Pillow)

How to Resize an Image in Python Using PIL (Pillow)

via Dev.tomary kariuki

Resizing images is a common task in data processing, web development, and automation. In Python, this can be done easily using the PIL (Pillow) library. This guide will walk you through the process step by step using real examples. This guide will walk you through the process step by step using real examples. šŸ“¦ Prerequisites Before you begin, ensure that Pillow is installed: pip install pillow Step 1: Import the Library Start by importing the Image module from PIL: >>> from PIL import Image Step 2: Open an Image You need to specify the full path to your image: >>> img = Image . open ( r " C:\Users\User\OneDrive\Documents\Stocktaking in a busy pharmacy (1).png " ) Step 3: Resize the Image You can resize the image by specifying the width and height (in pixels). Resize to 200x200 >>> image_resize = img . resize (( 200 , 200 )) >>> image_resize . save ( r " C:\Users\User\OneDrive\Documents\Stocktaking in a busy pharmacy (2).png " ) >>> image_resize . show () Resize to 100x100 >>> image_res

Continue reading on Dev.to

Opens in a new tab

Read Full Article
0 views

Related Articles