Skip to content
Menu
DevSecOps Now!!!
  • About
  • Certifications
  • Contact
  • Courses
  • DevSecOps Consulting
  • DevSecOps Tools
  • Training
  • Tutorials
DevSecOps Now!!!

A Complete Guide to Reducing Image Sizes in a WordPress Website Using ImageMagick

Posted on November 8, 2025

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

Images are one of the biggest contributors to website weight, especially WordPress websites where thousands of media files get uploaded over time. Large images affect page speed, search engine rankings, server storage, and hosting bills.
If you already have tens of thousands of images stored inside /wp-content/uploads, and you want to resize, compress, and overwrite them in place, ImageMagick is the most reliable tool to automate the job.

This tutorial will walk you through the entire process safely and clearly.


1. Understanding What We Are Trying to Achieve

Your WordPress website contains:

  • JPG/JPEG images
  • PNG images
  • WEBP images
  • Stored in thousands of subfolders, one for each month/year
  • All inside:
    /opt/lampp/htdocs/rajeshkumar.xyz/blog/wp-content/uploads

Your goal is:

  • Resize all images to 50% of their current width & height
  • Compress them to reduce file size
  • Keep the same filename, same folder
  • Apply this recursively to every subdirectory
  • Avoid errors and warnings
  • Do this safely and efficiently

ImageMagick is the perfect tool, but each image format works differently.
That is why the commands are not identical.


2. Installing ImageMagick (and Why โ€œmagickโ€ Was Not Found)

You ran:

sudo apt update
sudo apt install -y imagemagick

Ubuntu installed ImageMagick 6.x, not 7.x.
In ImageMagick 6, the command is:

convert
mogrify
which mogrify
mogrify -version

In ImageMagick 7, the command is:

magick

This is why your system replied:

Command 'magick' not found

Nothing is wrong.
Your system uses mogrify instead of magick.


3. Finding Your WordPress Uploads Folder

Most WordPress uploads are inside:

wp-content/uploads

In your case:

/opt/lampp/htdocs/example.xyz/blog/wp-content/uploads

You may set it as an environment variable:

UPLOADS="/opt/lampp/htdocs/example.xyz/blog/wp-content/uploads"

This keeps commands cleaner and reusable.


4. Before You Modify Anything: Create a Full Backup

This step is strongly recommended.
You should always take a snapshot before modifying thousands of files.

tar -C "$(dirname "$UPLOADS")" -czf \
  "$(basename "$UPLOADS")_backup_$(date +%F).tar.gz" \
  "$(basename "$UPLOADS")"

This creates a compressed backup file in the parent folder.

If anything goes wrong, you can restore easily.


5. How ImageMagick Works With Different Image Formats

ImageMagick does not treat all image formats the same.
Thatโ€™s why each format requires a different command.

JPG/JPEG

  • Supports lossy compression
  • Has a -quality setting
  • Contains EXIF rotation โ†’ needs -auto-orient

PNG

  • Lossless format
  • Does not support quality-based compression
  • Uses compression โ€œstrategyโ€ instead
  • Does not require orientation fixes

WEBP

  • Supports lossy size reduction
  • Supports โ€œqualityโ€
  • Does not use PNG compression flags

Because of these differences, each command must match the format.


6. Commands for Each Format

Below are the correct commands you can safely use.

6.1 PNG โ€” Resize + Compress (Lossless)

Your earlier attempt produced warnings because ImageMagick 6 does not support the compression-filter flag.
This is the correct version:

find "$UPLOADS" -type f -iname '*.png' -not -path '*/cache/*' -print0 \
| xargs -0 -n 50 -P 4 mogrify -strip -resize 50% \
  -define png:compression-level=5 \
  -define png:compression-strategy=1

This reduces PNG size without losing visual quality.


6.2 JPG / JPEG โ€” Resize + Quality Reduction (Lossy)

find "$UPLOADS" -type f \( -iname '*.jpg' -o -iname '*.jpeg' \) \
  -not -path '*/cache/*' -print0 \
| xargs -0 -n 50 -P 4 mogrify -auto-orient -strip -resize 50% -quality 70

This is the most effective size reduction.
Images become much smaller with acceptable quality.


6.3 WEBP โ€” Resize + Quality 70 (Lossy)

find "$UPLOADS" -type f -iname '*.webp' \
  -not -path '*/cache/*' -print0 \
| xargs -0 -n 50 -P 4 mogrify -strip -resize 50% -quality 70

This also reduces size dramatically while keeping good quality.


7. Understanding Why These Commands Are Different

This was your specific question, and here is the clear summary:

  • PNG is lossless โ†’ uses compression strategy instead of quality
  • JPG is lossy โ†’ requires -quality, supports -auto-orient
  • WEBP is modern lossy โ†’ supports -quality, no PNG flags
  • Each format has a different internal compression engine

Therefore, each command matches the technical behaviour of the format.


8. How To Skip WordPress Auto-Generated Thumbnails

WordPress creates many variants like:

image-150x150.jpg
image-300x300.png
image-1024x768.webp

If you want only original images, add this filter:

-not -regex '.*-[0-9]\{2,4\}x[0-9]\{2,4\}\..*'

Example for JPG:

find "$UPLOADS" -type f \( -iname '*.jpg' -o -iname '*.jpeg' \) \
  -not -path '*/cache/*' \
  -not -regex '.*-[0-9]\{2,4\}x[0-9]\{2,4\}\.jpe*g' \
  -print0 \
| xargs -0 -n 50 -P 4 mogrify -auto-orient -strip -resize 50% -quality 70

This prevents altering preview images WordPress uses internally.


9. How To Resize Only Large Images (Optional)

If you want to resize only โ€œbigโ€ images, not small ones:

-resize '2000x2000>'

The > symbol means โ€œresize only if larger thanโ€.

Example:

mogrify -resize '2000x2000>' -quality 70

10. Performance Tips for Tens of Thousands of Images

When processing 10,000+ images, a few adjustments matter:

Use parallel execution

-P 4 means 4 parallel processes.
If your CPU is strong, set -P 8 or -P 12.

Use batches

-n 50 processes 50 files per batch.
You can increase it to 100 for faster operations.

Avoid cache folders

The parameter -not -path '*/cache/*' avoids duplicate or unnecessary files.

Use SSD if possible

Image resizing is CPU + disk intensive.


11. How To Verify That Compression Worked

Pick a file and run:

identify -verbose file.jpg | grep "Geometry"

And:

ls -lh file.jpg

Compare:

  • Before and after image size
  • Pixel dimensions
  • Orientation
  • Metadata presence

12. What To Do If Something Goes Wrong

Since you took a tar backup, restoring is simple:

tar -C "$(dirname "$UPLOADS")" -xzf uploads_backup_YYYY-MM-DD.tar.gz

This overwrites all images with their original versions.


Post Views: 338
  • Image Sizes in a WordPress
  • Image Sizes in a WordPress Website
  • ImageMagick
  • magick
  • mogrify
  • Reducing Image Sizes
  • Reducing Image Sizes in a WordPress
  • Reducing Image Sizes in a WordPress Website
  • Reducing Image Sizes using ImageMagick
  • WordPress
Subscribe
Login
Notify of
guest
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
  • Incorrect definition of table mysql.column_stats
  • Mautic and PHP 8.3 Compatibility Guide (2026)
  • Certified AIOps Engineer: The Complete Career Path and Certification Guide
  • How to Rename Apache Virtual Host Files Safely (Step-by-Step Guide for Linux)
  • AIOps Foundation Certification: Everything You Need to Know to Get Certified
  • DevOps to Certified Site Reliability Professional: A Senior Mentorโ€™s Guide
  • Certified Site Reliability Manager Training, Preparation, and Career Mapping
  • Certified Site Reliability Architect: The Complete Career Guide
  • What Is a VPN? A Complete Beginner-to-Advanced Tutorial
  • How to Install, Secure, and Tune MySQL 8.4 on Ubuntu 24.04 for Apache Event MPM and PHP-FPM
  • Complete Guide to Certified Site Reliability Engineer Career
  • Certified DevSecOps Professional Step by Step
  • Certified DevSecOps Manager: Complete Career Guide
  • Certified DevSecOps Engineer: Skills, Career Path and Certification Guide
  • Step-by-Step: Become a Certified DevSecOps Architect
  • Tuning PHP 8.3 for Apache Event MPM and PHP-FPM on Ubuntu: A Complete Step-by-Step Production Guide
  • Complete Step-by-Step Guide to Configure Apache Event MPM, Create index.php, Set Up VirtualHost, and Fix Ubuntu Default Page
  • Convert XAMPP Apache to Event MPM + System PHP-FPM
  • The Gateway to System Observability Engineering (MOE)
  • How to Finetune Apache and Prove It Works: A Real-World Guide to Testing Performance, Concurrency, HTTP/2, Memory, CPU, and Security
  • Building a High-Performance Apache Event MPM + PHP-FPM + MariaDB Stack (Advanced Server Optimization Guide)
  • Master Infrastructure as Code: The Complete Hashicorp Terraform Associate Guide
  • Building a High-Performance Apache Server with Event MPM + PHP-FPM (Step-by-Step Guide)
  • Is XAMPP Safer for Production Than Using Apache and PHP as Root? 2026 Practical Guide
  • Unlock Cloud Security Expertise with Certified Kubernetes Security Specialist (CKS)
  • How to Fix wpDiscuz Not Replacing Default WordPress Comments in Block Themes
  • Complete Guide to Certified Kubernetes Application Developer Certification
  • Overview of Certified Kubernetes Administrator (CKA) Certification
  • How to Install and Configure XAMPP on Ubuntu 24 Server (Latest Version โ€“ 2026 Complete Guide)
  • Mastering the Google Cloud Professional DevOps Engineer

Recent Comments

  1. digital banking on Complete Tutorial: Setting Up Laravel Telescope Correctly (Windows + XAMPP + Custom Domain)
  2. SAHIL DHINGRA on How to Uninstall Xampp from your machine when it is not visible in Control panel programs & Feature ?
  3. Abhishek on MySQL: List of Comprehensive List of approach to secure MySQL servers.
  4. Kristina on Best practices to followed in .httacess to avoid DDOS attack?
  5. Roshan Jha on Git all Commands

Archives

  • April 2026
  • March 2026
  • February 2026
  • January 2026
  • December 2025
  • November 2025
  • October 2025
  • September 2025
  • August 2025
  • July 2025
  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022

Categories

  • Ai
  • AI Blogging
  • AiOps
  • ajax
  • Android Studio
  • Antimalware
  • Antivirus
  • Apache
  • Api
  • API Security
  • Api Testing
  • APK
  • Aws
  • Bike Rental Services
  • ChatGPT
  • Code Linting
  • Composer
  • cPanel
  • Cyber Threat Intelligence
  • Cybersecurity
  • Data Loss Prevention
  • Database
  • dataops
  • Deception Technology
  • DeepSeek
  • Devops
  • DevSecOps
  • DevTools
  • Digital Asset Management
  • Digital Certificates
  • Docker
  • Drupal
  • emulator
  • Encryption Tools
  • Endpoint Security Tools
  • Error
  • facebook
  • Firewalls
  • Flutter
  • git
  • GITHUB
  • Google Antigravity
  • Google play console
  • Google reCAPTCHA
  • Gradle
  • Guest posting
  • health and fitness
  • IDE
  • Identity and Access Management
  • Incident Response
  • Instagram
  • Intrusion Detection and Prevention Systems
  • jobs
  • Joomla
  • Keycloak
  • Laravel
  • Law News
  • Lawyer Discussion
  • Legal Advice
  • Linkedin
  • Linkedin Api
  • Linux
  • Livewire
  • Mautic
  • Medical Tourism
  • MlOps
  • MobaXterm
  • Mobile Device Management
  • Multi-Factor Authentication
  • MySql
  • Network Traffic Analysis tools
  • Paytm
  • Penetration Testing
  • php
  • PHPMyAdmin
  • Pinterest Api
  • Quora
  • SAST
  • SecOps
  • Secure File Transfer Protocol
  • Security Analytics Tools
  • Security Auditing Tools
  • Security Information and Event Management
  • Seo
  • Server Management Tools
  • Single Sign-On
  • Site Reliability Engineering
  • soft 404
  • software
  • SuiteCRM
  • SysOps
  • Threat Model
  • Twitter
  • Twitter Api
  • ubuntu
  • Uncategorized
  • Virtual Host
  • Virtual Private Networks
  • VPNs
  • Vulnerability Assessment Tools
  • Web Application Firewalls
  • Windows Processor
  • Wordpress
  • WSL (Windows Subsystem for Linux)
  • X.com
  • Xampp
  • Youtube
©2026 DevSecOps Now!!! | WordPress Theme: EcoCoded
wpDiscuz