When you’re assembling documentation, preparing a portfolio, or sending photos for an application, you often need smaller image files that still keep important metadata like capture date and camera information. In this tutorial, we’ll build a simple macOS workflow to compress photos from the terminal while preserving EXIF data.

Instead of relying on online tools that might strip metadata or upload personal images, you’ll run everything locally, with full control over size and quality.

The Challenge

You have several options for shrinking images on a Mac:

  1. Online compressors are quick, but many remove metadata for privacy or size, and your files pass through third-party servers.
  2. Manual export from Preview or a graphics editor works, but repeating it for many files is slow and easy to get inconsistent.

In this article, we’ll use ImageMagick from the terminal. It lets you dial in compression levels, keep metadata by default, and batch-process entire folders.

Creating the workflow: step-by-step guide to compressing photos

We’ll:

  • Install ImageMagick with Homebrew.
  • Compress a single photo while preserving metadata.
  • Combine resizing and compression.
  • Batch-compress a whole folder of photos.

Everything runs in a few simple commands.

Installing ImageMagick

Open Terminal and install ImageMagick using Homebrew:

Terminal
brew install imagemagick

If macOS prompts you to install Command Line Tools, follow the prompt, then repeat the command. After installation, verify it’s available:

Terminal
magick -version

You should see version information and supported formats.

Compressing a single photo while preserving metadata

Let’s say you have a folder ~/Pictures/Application Photos with a file called portrait-original.jpg. Navigate there:

Terminal
cd ~/Pictures
ls
cd "Application Photos"
ls

To create a smaller copy while keeping EXIF metadata, run:

Terminal
magick "portrait-original.jpg" -quality 75 "portrait-compressed.jpg"

This command:

  • Re-encodes the JPEG at quality 75 (a solid compromise between size and quality).
  • Writes to a new file, so the original stays untouched.
  • Keeps metadata, because we haven’t used any flag that strips it (such as -strip).

Open both files in Preview, choose Tools > Show Inspector (cmd+I), and compare the Info tab to confirm that details like capture date and camera model are still present in the compressed version.

If you need stronger compression, you can lower the quality value:

Terminal
magick "portrait-original.jpg" -quality 60 "portrait-compressed.jpg"

Always inspect the result to ensure the image still meets your needs.

Resizing and compressing together

Sometimes, file size is driven by image dimensions as much as quality. If you want to limit images to a maximum of 1600 pixels in either dimension, you can resize and compress in a single command:

Terminal
magick "portrait-original.jpg" -resize 1600x1600\> -quality 75 "portrait-1600px.jpg"

Here:

  • -resize 1600x1600\> tells ImageMagick to shrink the image only if it’s larger than 1600 pixels on either side; smaller images are left alone. The backslash stops the shell from reading > as a redirect.
  • -quality 75 still controls JPEG compression.
  • Metadata remains unless you explicitly remove it.

This is ideal for preparing photos for web or email where huge originals aren’t necessary.

Batch-compressing a folder of photos

If you have many images in the same folder, you can compress them all in one go. From inside your photo folder, list the files:

Terminal
cd ~/Pictures/"Application Photos"
ls

If you see a collection of .jpg files like:

Output
portrait-original.jpg
document-scan-1.jpg
document-scan-2.jpg

you can run:

Terminal
for f in *.jpg; do
  magick "$f" -quality 75 "${f%.jpg}-compressed.jpg"
done

This loop:

  • Iterates over each .jpg file.
  • Creates a -compressed.jpg version next to it.
  • Preserves metadata by default.

To resize and compress each file at the same time:

Terminal
for f in *.jpg; do
  magick "$f" -resize 1600x1600\> -quality 75 "${f%.jpg}-compressed.jpg"
done

Run a loop once per folder: a second run would also pick up the -compressed.jpg copies. You can tweak the quality level and max size until you find a balance that works for your purpose.

Verifying and using your compressed photos

Once the batch completes:

  • Use Finder’s Get Info to check that the compressed files are significantly smaller.
  • Use Preview’s Inspector to confirm that EXIF and other metadata are present in the new images.
  • Use the compressed versions for submissions, uploads, and sharing, while keeping the originals archived.

Conclusion

By building this command-line workflow, you avoid repetitive export steps, keep control over your data, and can quickly adapt quality and size for any new project on your Mac.