Skip to main content
Inspiring
Feb 21, 2023 9:40 AM UTC
Answered

Resizing several images

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

D Fosse
D FosseCorrect answer
Community Expert
Feb 21, 2023 12:07 PM UTC

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.

7 replies

Participant
Mar 24, 2025 11:28 AM UTC

 

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

Translate
D Fosse
Community Expert
D FosseCommunity ExpertCorrect answer
Community Expert
Feb 21, 2023 12:07 PM UTC

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.

Translate
LenouAuthor
Inspiring
Feb 22, 2023 2:11 PM UTC

Thank you very much! It seems to work well!

Translate
Abambo
Community Expert
Community Expert
Feb 21, 2023 9:55 AM UTC

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

Translate
ABAMBO | Hard- and Software Engineer | Photographer