Last updated: February 5, 2025

<span aria-hidden="true" id="create-image-collages-with-imagemagick-cli"></span>

# Create image collages with ImageMagick CLI

![Tim Koschützki](/assets/images/teammates/avatar-tim-kos-1.jpg?dpl=dpl_3fBRD5jmFtSDABLXGJJyXU1nVXf8)

**Tim Koschützki**

Co-founder · Berlin, Germany · Show bio

[](https://x.com/tim%5Fkos)[](https://github.com/tim-kos)

Creating image collages is a great way to combine multiple photos into a single, eye-catching composition—ideal for portfolios, event highlights, or gallery displays. In this post, we will explore how to use ImageMagick's command-line tools to automate collage creation, customize layouts, and process multiple directories in batch.

<span aria-hidden="true" id="set-up-imagemagick"></span>

## Set up ImageMagick

First, install ImageMagick on your system. For Ubuntu/Debian:

```bash
sudo apt-get update
sudo apt-get install imagemagick

```

Verify your installation and check the version:

```bash
# For ImageMagick 7
magick --version
# For ImageMagick 6
convert --version

```

**Note**

Commands in this guide work with both ImageMagick 6 and 7. For version 7, replace `convert`with `magick`.

<span aria-hidden="true" id="configure-resource-limits"></span>

## Configure resource limits

Before processing large batches, adjust ImageMagick's resource limits to prevent memory issues:

```bash
# Check current limits
identify -list resource

# Edit policy file
sudo nano /etc/ImageMagick-6/policy.xml  # or /etc/ImageMagick-7/policy.xml

```

Adjust these values based on your system's capabilities:

```xml
<policy domain="resource" name="memory" value="256MiB"/>
<policy domain="resource" name="disk" value="1GiB"/>

```

<span aria-hidden="true" id="prepare-your-images"></span>

## Prepare your images

For consistent collages, normalize your image sizes. Here are the commands for both ImageMagick versions:

```bash
# ImageMagick 6
convert input.jpg -resize 200x200 resized.jpg

# ImageMagick 7
magick input.jpg -resize 200x200 resized.jpg

```

To process multiple images:

```bash
for img in *.jpg; do
  magick "$img" -resize 200x200 "resized_$img"
done

```

<span aria-hidden="true" id="create-a-collage-using-montage"></span>

## Create a collage using montage

The `montage` command combines images into a grid layout. Basic usage:

```bash
montage image1.jpg image2.jpg image3.jpg -tile 3x1 -geometry +2+2 collage.jpg

```

Command options explained:

* `-tile 3x1`: Three columns, one row
* `-geometry +2+2`: 2-pixel spacing between images

<span aria-hidden="true" id="customize-your-layout"></span>

## Customize your layout

Create more sophisticated collages with these options:

```bash
# Add background color and frame
montage *.jpg -tile 3x -geometry +4+4 -frame 5 \
  -background '#336699' framed_collage.jpg

# Create polaroid-style layout
montage *.jpg -tile 3x -geometry +4+4 -shadow \
  -background white -polaroid 0 polaroid_collage.jpg

# Add title to each image
montage *.jpg -title '%f' -tile 3x -geometry +4+4 \
  -background '#f0f0f0' titled_collage.jpg

```

<span aria-hidden="true" id="batch-processing-with-error-handling"></span>

## Batch processing with error handling

This script processes multiple directories with error handling and logging:

```bash
#!/bin/bash

# Set up logging
exec 1> >(tee "collage_process.log") 2>&1

for dir in */; do
  if [ -d "$dir" ]; then
    echo "Processing directory: $dir"

    # Count JPG files
    count=$(find "$dir" -maxdepth 1 -type f -name "*.jpg" | wc -l)

    if [ $count -eq 0 ]; then
      echo "No JPG files found in $dir"
      continue
    fi

    # Create collage with error handling
    montage "$dir"*.jpg -tile 3x -geometry +2+2 \
      "${dir%/}-collage.jpg" 2>/dev/null || {
      echo "Error creating collage for $dir"
      continue
    }

    echo "Successfully created collage for $dir"
  fi
done

```

<span aria-hidden="true" id="troubleshooting"></span>

## Troubleshooting

Common issues and solutions:

* If montage fails with "unable to open image", verify file paths and permissions
* For "no decode delegate" errors, install additional format support:

```bash
sudo apt-get install libheif-dev libjpeg-dev libpng-dev  
```

* For memory errors, adjust resource limits as shown in the configuration section

<span aria-hidden="true" id="conclusion"></span>

## Conclusion

ImageMagick's CLI tools provide powerful options for creating custom image collages efficiently. By combining these commands with shell scripts, you can automate the creation of professional-looking collages for various purposes. For advanced image processing needs, consider exploring Transloadit's image processing service, which builds upon ImageMagick's capabilities with additional features and cloud-based processing.

\#imagemagick#cli#image-processing-service#batch-processing

### 👩‍💻 Join 20k+ developers

Sign up for our [monthly newsletter](/newsletters.md) to receive direct links to 3 exclusive tech — and 2 product updates. No less, no more.

Your email:

Get access

## File uploading and encoding. Made simple.

Transloadit streamlines file handling for developers, trusted by brands like Coursera and The New York Times. We’re known for a reliable API, top-notch support, and a strong commitment to open source, with projects like [Uppy⁠](https://uppy.io) and [Tus⁠](https://tus.io) setting standards in file processing.

[Sign up](/c/)[Book a Demo](https://survey.typeform.com/to/kRg47Xi5)

No credit card needed · 5 GB included in the free plan

Cancel anytime
