Skip to main content
Inspiring
February 21, 2023
Answered

Resizing several images

  • February 21, 2023
  • 3 replies
  • 1421 views

Hello! Do someone know if it is possible to resize multiple images with a script even through they have different sizes?

Correct answer D Fosse

If the goal is a standard size, File > Automate > Fit Image is what you want for this. It can be used in actions, a script is not necessary.

 

It will work on both portrait and landscape, resizing the longest side. It can either enlarge if applicable, or not.

3 replies

Participant
March 24, 2025

 

1. Python Solution (PIL - Pillow)

You can use the Pillow (PIL) library to resize multiple images in a folder, regardless of their original sizes.

Example: Resize all images to 500x500 pixels

 

python
from PIL import Image import os input_folder = "images/" # Folder containing images output_folder = "resized_images/" # Output folder # Create output directory if it doesn't exist os.makedirs(output_folder, exist_ok=True) # Loop through all images in the input folder for filename in os.listdir(input_folder): if filename.endswith((".jpg", ".jpeg", ".png", ".bmp", ".gif")): img_path = os.path.join(input_folder, filename) img = Image.open(img_path) # Resize the image while maintaining aspect ratio img_resized = img.resize((500, 500), Image.ANTIALIAS) # Save the resized image img_resized.save(os.path.join(output_folder, filename)) print("Batch image resizing completed!")

 

✔ This script resizes all images in the images/ folder and saves them to resized_images/.


2. Python Solution (OpenCV)

If you prefer OpenCV, use the following script:

 

python
import cv2 import os input_folder = "images/" output_folder = "resized_images/" os.makedirs(output_folder, exist_ok=True) for filename in os.listdir(input_folder): if filename.endswith((".jpg", ".jpeg", ".png")): img_path = os.path.join(input_folder, filename) img = cv2.imread(img_path) # Resize image while keeping aspect ratio img_resized = cv2.resize(img, (500, 500)) cv2.imwrite(os.path.join(output_folder, filename), img_resized) print("Images resized successfully!")

 

 

3. Using ImageMagick (Command Line)

If you prefer a command-line approach, ImageMagick can resize all images in a folder:

 

bash
magick mogrify -path resized_images -resize 500x500 images/*.jpg

✔ This command resizes all .jpg images in the images/ folder and saves them to resized_images/.


Which One Should You Use?

  • Python (PIL or OpenCV) – Best for automation in scripts or web applications.

  • ImageMagick – Fastest for bulk resizing via command line

D Fosse
Community Expert
D FosseCommunity ExpertCorrect answer
Community Expert
February 21, 2023

If the goal is a standard size, File > Automate > Fit Image is what you want for this. It can be used in actions, a script is not necessary.

 

It will work on both portrait and landscape, resizing the longest side. It can either enlarge if applicable, or not.

LenouAuthor
Inspiring
February 22, 2023

Thank you very much! It seems to work well!

Abambo
Community Expert
Community Expert
February 21, 2023

Yes, it is possible. But you need to define the criteria. How will the final size be determined?

ABAMBO | Hard- and Software Engineer | Photographer