How to Compress Images on Linux (Complete Guide)
Large image files slow down websites, eat up storage, and make file sharing painful. If you're looking for a reliable way to compress images on Linux, the good news is that the platform offers some of the best free tools available for the job — both from the command line and through graphical apps.
This guide walks through practical, tested methods to shrink PNG and JPEG files on Linux while keeping visual quality intact. Whether you're a beginner who just wants a quick fix or a developer who needs to batch-process thousands of files, you'll find an approach that fits.
Why Image Compression Matters
Every image on a webpage, in an app, or in a shared folder takes up bandwidth and storage. Uncompressed images can be 2 to 10 times larger than they need to be without any noticeable difference in quality.
For website owners, this directly affects page load speed — a factor that influences both user experience and search engine rankings. For developers and content creators, smaller files mean faster uploads, quicker backups, and lower hosting costs.
There are two main types of compression to understand before choosing a tool:
- Lossless compression — reduces file size without discarding any image data. The result is pixel-for-pixel identical to the original.
- Lossy compression — removes some data that's less noticeable to the human eye, achieving much smaller file sizes with a small, often invisible, quality trade-off.
Most practical workflows use a mix of both, depending on the image type and its purpose.
Best Tools to Compress Images on Linux
Linux has a strong ecosystem of open-source compression tools. Below are the most reliable ones, split by image format.
Tools for PNG Compression
| Tool | Type | Best for |
|---|---|---|
pngquant | Lossy (visually lossless) | Fast, major size reduction |
oxipng | Lossless | Safe, zero quality loss |
optipng | Lossless | Older but stable alternative |
Tools for JPEG Compression
| Tool | Type | Best for |
|---|---|---|
jpegoptim | Lossy/Lossless | Quick quality-based compression |
mozjpeg | Lossy | Higher compression efficiency than standard JPEG encoders |
Tools for Multiple Formats
| Tool | Type | Best for |
|---|---|---|
ImageMagick | Lossy/Lossless | All-purpose image processing and resizing |
GIMP | GUI | Manual, visual editing and export control |
| Squoosh (web app) | Lossy/Lossless | Visual before/after comparison, no install needed |
Most of these are available directly through your distribution's package manager, which makes installation straightforward.
How to Compress PNG Images on Linux
PNG files use lossless compression by design, which is why they tend to be larger than JPEGs. The most effective way to shrink them without visible quality loss is through palette-based lossy compression, combined with lossless optimization.
Step 1: Install pngquant
On Debian/Ubuntu-based systems:
sudo apt install pngquant
On Arch-based systems (Arch, Manjaro, CachyOS):
sudo pacman -S pngquant
On Fedora:
sudo dnf install pngquant
Step 2: Compress a Single File
pngquant --quality=80-95 --output compressed.png input.png
The --quality flag sets an acceptable quality range. pngquant will use the minimum compression needed to stay within that range, so image fidelity stays close to the original.
Step 3: Add Lossless Optimization (Optional)
For an extra size reduction with zero quality trade-off, run the output through oxipng:
oxipng -o 4 --strip safe compressed.png
This removes redundant metadata and re-compresses the file structure without touching a single pixel.
Step 4: Batch Compress a Folder
mkdir compressed
for f in *.png; do
pngquant --quality=80-95 --skip-if-larger --output "compressed/$f" "$f"
done
For large batches, running files in parallel across CPU cores speeds this up significantly — a topic covered in more detail in a dedicated PNG batch-compression guide.
How to Compress JPEG Images on Linux
JPEG is already a lossy format, so compression here mostly means adjusting the level of lossy compression to hit the right size-to-quality balance.
Step 1: Install jpegoptim
sudo apt install jpegoptim # Debian/Ubuntu
sudo pacman -S jpegoptim # Arch-based
sudo dnf install jpegoptim # Fedora
Step 2: Compress with a Target Quality
jpegoptim --max=85 photo.jpg
This re-encodes the image so it doesn't exceed 85% quality, which is usually indistinguishable from the original to the naked eye while cutting file size noticeably.
Step 3: Strip Metadata for Extra Savings
Photos often carry EXIF metadata (camera model, GPS location, timestamps) that adds unnecessary weight:
jpegoptim --strip-all --max=85 photo.jpg
Step 4: Batch Process a Folder
jpegoptim --strip-all --max=85 *.jpg
jpegoptim processes files in place by default, so it's worth testing on a copy first if you want to preserve the originals.
Compressing Images with ImageMagick (All-in-One Option)
If you need one tool that handles resizing, format conversion, and compression together, ImageMagick is a solid choice.
sudo apt install imagemagick
Compress and resize in a single command:
convert input.jpg -quality 80 -resize 1600x1600\> output.jpg
-quality 80sets the compression level.-resize 1600x1600\>only shrinks images larger than 1600px on either side, leaving smaller ones untouched.
This is particularly useful when preparing a batch of product photos or blog images that need to be a consistent maximum size — a workflow familiar to anyone generating product images for e-commerce or small business use.
Using a GUI: GIMP and Web-Based Tools
Not everyone wants to use the terminal, and that's fine — Linux has solid graphical options too.
GIMP
- Open the image in GIMP.
- Go to File → Export As.
- Choose PNG or JPEG as the format.
- In the export dialog, adjust the compression level (PNG) or quality slider (JPEG).
- Preview the file size estimate before saving.
GIMP gives full manual control, which is useful for one-off edits where you want to see the visual result before committing.
Squoosh (Browser-Based)
Squoosh is a free web app built by Google that lets you compare compression settings side-by-side in real time, right in the browser. It works entirely offline once loaded and doesn't require installing anything — a convenient option for quick, one-time compressions.
Choosing the Right Compression Level
There's no single "best" setting — it depends on how the image will be used.
- Web thumbnails and icons: aggressive compression is fine; quality 60–75 is usually unnoticeable at small sizes.
- Blog and article images: quality 75–85 balances size and clarity well.
- Product photography or portfolio images: stay at quality 85–95 to preserve fine detail.
- Print or archival use: avoid lossy compression altogether; use lossless tools only.
A practical approach is to compress, then view the result at actual size before deciding if it's acceptable.
Common Mistakes to Avoid
- Compressing already-compressed JPEGs repeatedly. Each re-save introduces new lossy artifacts — always compress from the original source file when possible.
- Using the same quality setting for every image type. A quality setting that works for a photo may over-compress a graphic with sharp text or lines.
- Skipping a backup before batch operations. Some tools overwrite files in place; always test on a copy first.
- Ignoring metadata. EXIF and color profile data can add unnecessary file size, especially on photos straight from a camera or phone.
- Choosing PNG for photographs. PNG is lossless and ideal for graphics, logos, and screenshots — but it's usually the wrong format for photos, where JPEG or WebP compresses far more efficiently.
Frequently Asked Questions
Does compressing an image on Linux reduce its quality?
It depends on the method. Lossless tools like oxipng or optipng don't reduce quality at all. Lossy tools like pngquant or jpegoptim can reduce quality slightly, but at moderate settings (80–95%), the difference is usually invisible to the eye.
What's the best command-line tool to compress images on Linux?
For PNG, pngquant combined with oxipng is a reliable, widely used combination. For JPEG, jpegoptim is fast and simple. Both are actively maintained and available in most distribution repositories.
Can I compress images without losing any quality at all?
Yes — use lossless tools such as oxipng, optipng, or jpegoptim with the --strip-all flag but no quality reduction. These only remove redundant data and metadata, not image information.
Is WebP better than PNG or JPEG for compression? WebP generally produces smaller files than both PNG and JPEG at comparable quality, and it's well supported by modern browsers. Converting to WebP is worth considering for web use, though PNG and JPEG remain more universally compatible for other purposes.
How do I compress hundreds of images at once on Linux?
Combine a compression tool with a loop or a parallel processing tool like xargs -P or GNU parallel to process multiple files simultaneously using all available CPU cores, which speeds up large batches significantly.
Do I need to install anything extra, or does Linux compress images by default?
Linux doesn't compress images automatically — you need a dedicated tool such as pngquant, jpegoptim, or ImageMagick, most of which are available directly through your distribution's package manager.
Conclusion
Learning how to compress images on Linux doesn't require complex software or paid subscriptions — a handful of well-maintained, open-source tools cover nearly every use case, from quick one-off edits in GIMP to fully automated batch pipelines using pngquant, oxipng, and jpegoptim. The key is matching the tool and quality setting to the image's actual purpose, whether that's a lightweight web thumbnail or a high-fidelity print asset.
Start small: pick one tool from this guide, test it on a handful of images, and compare the before-and-after file sizes yourself. Once you're comfortable with the results, scaling up to batch processing is a natural next step.

