Resize image

Resize image with Python

200x200
400x400

Kacper Walczak · 28-10-2023

Resize img with PIL library

Get to know how to use PIL library

for Python img resize solution.

How to resize image with Python?

You can use PIL library to resize your images. PIL is a Python Imaging Library. It is free and open-source library. It supports many file formats and provides powerful image processing and graphics capabilities.

Other libraries that you can use to resize images are:

  • OpenCV
  • Scikit-image
  • Python Wand
  • PythonMagick
  • Pyvips

Install PIL library

pip install Pillow

Resize image

from PIL import Image
 
 
class ImageResizer:
    @staticmethod
    def resize(file_path: str, width=100, height=100) -> Image:
        image = Image.open(file_path)
        new_image = image.resize((width, height))
        return new_image
 
 
if __name__ == "__main__":
    new_img = ImageResizer.resize(file_path="dalle_onion_img.png", width=200, height=200)
    new_img.save(f"img_resized(x:{200},y:{200}).png")

That's it! Now you can use this code to resize your images.

READ

Latest readings

  • Readings are sites which will help you with detailed

  • information about given topic. Read latest ones from Learn.

AI

06-03-2026

Local Voice Assistant with Ollama
  • Build your own local voice assistant powered by Ollama.

AI

06-03-2026

AI YouTube Thumbnail Generator
  • Generate YouTube thumbnails with FastAPI and Ollama.

Architecture

05-09-2024

Graph DB usage comparison
  • Compare Neo4j and Tigergraph databases, which is easier to work with, etc.