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

Published: (April 7, 2026 at 12:10 PM EDT)
1 min read
Source: Dev.to

Source: Dev.to

Installation

pip install pillow

Importing the library

from PIL import Image

Resizing an image

# Open the original image
img = Image.open(r"C:\Users\User\OneDrive\Documents\Stocktaking in a busy pharmacy (1).png")

# Resize to 200×200 pixels
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 100×100 pixels
image_resize = img.resize((100, 100))
image_resize.save(r"C:\Users\User\OneDrive\Documents\Stocktaking in a busy pharmacy (3).png")
image_resize.show()

Working with another image

img = Image.open(r"C:\Users\User\OneDrive\Documents\Gemini_Generated_Image_yd8egyd8egyd8egy.png")
image_resize = img.resize((100, 100))
image_resize.save(r"C:\Users\User\OneDrive\Documents\Gemini_Generated_Image_yd8egyd8egyd8egy(1).png")
image_resize.show()

Important notes

  • Always include the full file path and correct file extension (.png, .jpg, etc.).
  • Ensure the file exists at the specified location.
  • Python is case‑sensitive; Image must be capitalized.
  • Prefix the path with r"" (raw string) to avoid issues with backslashes.
0 views
Back to Blog

Related posts

Read more »