Converting Thousands of Images in Bulk on macOS

Converting Thousands of Images in Bulk on macOS

Introduction

The other day, a client came to us with a unique request: resize thousands of images with completely different dimensions and aspect ratios so that, when imported into their website, the product images would appear as visually consistent as possible.

Here’s how we tackled the problem and the solution we implemented.

The Problem

One of our longstanding clients runs a PrestaShop online store with several thousand products.

Their design is meticulously crafted, and they pay special attention to their product imagery, producing all the photographic material themselves.

Recently, a supplier offered the ability to import their entire catalogue into the store and synchronise prices. This wasn’t typical dropshipping since our client maintains their own stock, but they wanted the ability to synchronise new products, removed items, and prices with the supplier’s catalogue.

We employed a custom PHP script for product synchronisation. However, upon analysing the images, we encountered a significant challenge. The supplier stored all the images in a shared folder on a popular cloud storage service. After downloading the entire collection, the situation was overwhelming: around 6,500 images with varying sizes, resolutions, and aspect ratios (the ratio of width to height).

Our client’s store uses square product images sized at 800x800px. We needed to standardise this entire set of images to enable bulk product imports while ensuring the visual consistency of the product pages.

Goals

The objectives for this task were as follows:

• Fit all images into an 800x800px canvas.

• Avoid distortion of the original images (preserving their original aspect ratio).

• Fill any empty spaces with a white background.

• Retain the original file names for use in bulk imports.

The Solution

For this task, we used ImageMagick.

ImageMagick is an incredibly powerful open-source software tool for creating, editing, converting, and processing images in various formats. It works from the command line, making it ideal for automating image-related tasks, particularly when dealing with bulk file manipulation.

Key Features of ImageMagick

• Format Conversion: Supports converting images between numerous formats, including JPEG, PNG, TIFF, BMP, GIF, WebP, and more.

• Resizing and Scaling: Adjust image dimensions while maintaining proportions or forcing specific sizes.

• Cropping and Smart Cropping: Manually crop images or crop based on key areas.

• Effects: Apply filters, borders, shadows, and other visual effects.

• Text or Watermark Overlays: Add text or watermarks to images.

• Generate Images from Scratch: Create gradients, patterns, or custom backgrounds.

• Advanced Colour Editing: Adjust colours, apply greyscale effects, or convert to specific colour palettes.

• Automation: Process hundreds or thousands of images with a single command or script.

ImageMagick supports over 100 file formats, including:

• Common: JPEG, PNG, GIF, BMP, TIFF.

• Advanced: WebP, SVG, HEIC, PDF.

• Specialised: FITS (astronomy), DPX (cinema), and more.

Given ImageMagick’s extensive capabilities and our macOS-based workflow, it was the perfect solution for our client’s needs. Here’s how we installed ImageMagick and processed the client’s images in bulk.

Deploying the Solution

First, we installed ImageMagick on macOS Sequoia 15.1, using a MacBook Pro with an M3 Pro processor.

To install the repository, we first installed Homebrew.

Homebrew is a package manager for macOS (and Linux) that simplifies the installation, updating, and management of software from the command line. It’s particularly useful for developers, system administrators, and advanced users who need open-source tools and utilities not available via the macOS App Store.

Steps to Install and Use ImageMagick


1. Install Homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"


2. Install ImageMagick

brew install imagemagick


3. If the “brew” command isn’t recognised:


a) Determine your terminal type:

echo $SHELL

b1) Add Homebrew to your terminal (zsh):

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zshrc
eval "$(/opt/homebrew/bin/brew shellenv)"

b2) Add Homebrew to your terminal (bash):

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile
eval "$(/opt/homebrew/bin/brew shellenv)"

c) Load your shell configuration:


• For zsh:
source ~/.zshrc

• For bash:
source ~/.bash_profile

4. Resize Images into a Square Canvas

Replace [source_directory] and [destination_directory] with your local paths:

find [source_directory] -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.gif" -o -iname "*.bmp" -o -iname "*.tiff" -o -iname "*.webp" \) -exec sh -c '
for img do
  filename=$(basename "$img")
  magick "$img" -resize 800x800 -gravity center -background white -extent 800x800 "[destination_directory]/$filename"
done
' sh {} +

Result

After approximately 10 minutes, the entire image collection was successfully converted, allowing us to complete the bulk product import seamlessly.

Need Help with Bulk Product Imports?

Get in touch with us!

We’re specialists and can help you streamline your online store’s operations.

Share this post :

Leave a Reply

Your email address will not be published. Required fields are marked *