October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Batch Compress Images from the Command Line

Batch process images with ImageMagick while preserving originals, choosing format-specific settings, and checking the visual and file-size results.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a straightforward batch, ImageMagick’s magick mogrify can process every matching image in a folder. The catch is that mogrify overwrites those files by default, so use a separate output location or test on copies if you need to keep your originals. Also, “compress” can mean resizing, changing encoder settings, or converting formats—each affects images differently.

Choose what “compress” should do

Before running a batch command, decide whether you want fewer pixels, smaller encoded files, or both. Those are different operations:

As an Amazon Associate I earn from qualifying purchases.

  • Resize: reduces pixel dimensions. It can lower file size, but also makes the image physically smaller in pixel terms.
  • Lossy encoding: can reduce file size by discarding image detail. The result depends on the image and encoder settings, so inspect the output.
  • Lossless optimization: aims to reduce file size without changing the decoded image pixels. The available controls depend on the format and encoder.
  • Format conversion: may reduce size, but can also change image characteristics or discard information. Choose the destination format for how the images will be used.

ImageMagick supports batch processing and format-specific controls, but the command alone cannot promise a particular file-size reduction.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Batch-process matching files in one folder

ImageMagick documents this JPEG resize example:

magick mogrify -resize 256x256 *.jpg

Run it from the folder containing the JPEGs. The wildcard *.jpg selects matching files in the current directory; it does not search nested folders. The operation resizes the matching images and, because it uses mogrify, changes the originals. See ImageMagick’s Mogrify documentation.

#1 Best Overall
Nero AI Image Upscaler 365 | Enlarge Images & Sharpen Photos | AI Upscaling to 4K | Fix Blurry & Low-Resolution Pictures | Easy Photo Optimization | 1 PC | Windows 11/10
  • ✔️ AI Upscaling up to 8K: Enlarge small, low-resolution, or old photos with crisp details, clean edges, and fewer artifacts — perfect for prints, social media, blogs, and online galleries.
  • ✔️ Fix blurry or noisy photos: AI restores clarity by enhancing textures, sharpening faces, hair, and fine details while reducing noise and JPEG compression errors.
  • ✔️ Ideal for family photos, scans & mobile images: Improve pictures from smartphones, tablets, digital cameras, scanners, and old archives with professional-quality results.
  • ✔️ Fast & easy 1-click enhancement: Batch-process multiple photos at once and improve image quality instantly — no editing experience required.
  • ✔️ Reliable results & broad file support: Works with JPG, PNG, TIFF and more — stable AI processing even on old, compressed or damaged photos.

To retain the source PNGs while writing JPEG copies, ImageMagick documents:

magick mogrify -format jpg *.png

This leaves the PNG inputs in place and creates JPEG outputs. Since JPEG is a lossy format, check that it suits the images before converting a whole collection.

Keep originals safe

ImageMagick’s command-line tools documentation explains: “Mogrify overwrites the original image file, whereas, magick writes to a different image file.” For a batch that must not alter the source collection, choose a workflow that writes distinct output files or use an output path or format option that preserves the inputs. Create the destination directory first if the command requires an existing directory.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Make a backup or copy a small representative sample to a test folder.
  2. Run the command on that sample rather than the only copy of the collection.
  3. Compare the resulting images visually and check their file sizes.
  4. Only process the full set after confirming the output and destination behavior.

See ImageMagick’s command-line tools documentation for the distinction between mogrify and magick.

Set quality for the output format

The meaning of -quality is format-dependent; its number is not a universal “compression percentage.” ImageMagick documents different behavior for JPEG and PNG in its command-line options.

JPEG

For JPEG, quality is on a 1–100 scale: 1 gives the lowest image quality and highest compression, while 100 gives the best quality and least effective compression. Default behavior depends on whether ImageMagick can estimate quality from the input. A setting such as -quality 80 does not guarantee a specific reduction in bytes; results vary with the source image and encoding.

PNG

For PNG, the quality value controls zlib compression level and filter selection. Its scale is not directly comparable to JPEG’s visual-quality scale. Test the resulting PNGs rather than assuming that a familiar JPEG number has the same meaning.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

WebP

WebP offers additional encoder options that trade encoding speed, compressed size, and quality. The right balance depends on the intended use; consult ImageMagick’s WebP documentation and inspect sample output before applying settings at scale.

Best Value
Scrivar PDF Pro - Organize, Edit, Compress, Convert, Merge, eSign, OCR & 30+ tools | Lifetime License
  • EVERY PDF TOOL UNLOCKED - 30+ tools in one app: edit text and images, convert, merge, split, compress, sign, OCR, redact, watermark, batch process, and more. No feature gates, no upsells, nothing held back.
  • PAY ONCE, OWN FOREVER — A one-time purchase, not a subscription. Other apps runs $240/year — Scrivar is yours for life, with free updates included.
  • UNLIMITED eSIGN, BUILT IN — Send contracts and forms for signature and track every step. Recipients sign in their browser with no account or app needed. Replace DocuSign and save hundreds a year.
  • PC, MAC, AND WEB — Install on any Win 10/11 PC or macOS 11+ Mac (Intel or Apple Silicon), or work in your browser at scrivar.com. Same tools, same account, everywhere you work.
  • OCR + FULL OFFICE CONVERSION — Turn scanned documents into searchable, selectable text, and convert PDFs to and from Word, Excel, and PowerPoint with formatting kept intact.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Handle nested folders and filenames carefully

A shell wildcard such as *.jpg is convenient for one directory, but it does not provide universal recursive traversal. Recursive discovery and reliable handling of filenames with spaces vary by shell and operating system. Use a file-list or shell-loop workflow appropriate to your environment, and quote filenames so spaces are treated as part of a path rather than as separators. Avoid assuming a command written for one shell will work unchanged in another.

Mixed extensions need similar care: a pattern for *.jpg will not select PNG or WebP files. Process each intended format deliberately, or use a file-list workflow that explicitly selects the formats you want. Before using a less common format, verify that your installed ImageMagick build supports the required input and output codec.

Check the results, not just the command

There is no universal compression ratio to expect. The output size depends on the source image, format, encoder, and settings. After a small test batch, check both the byte size and visual appearance of representative images, including detailed areas and edges. Keep the originals until you have confirmed that the output meets your needs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.