🚀 Is building a website too difficult? Let me guide you step by step—Learn about the 「Naibabiji WordPress Website Building Coaching Service」 →

Method for Batch Compressing WordPress Images on Linux VPS

First timebuilding your own websiteFriends may not know that images uploaded to the website need to have their dimensions compressed, otherwise they will occupy a lot of hard drive space over time. Naiba recently encountered several WordPress e-commerce websites where image attachments filled up the disk. So, here's how to batch compress image dimensions on a Linux VPS.Prerequisite:This method is only for Linux systemsVPS, if you are usingWordPress hosting, then this method cannot be used.Specific Method:Here we use the tools OptiPNG and jpegoptim along with a script to achieve automatic image dimension compression. 1. Install OptiPNG and jpegoptim
#安装epel源
yum -y install epel-release
#安装OptiPNG
yum -y install optipng
#安装jpegoptim
yum -y install jpegoptim
The above command is for CentOS systems. If you are using Debian, Ubuntu, or other systems, please search for the corresponding command yourself. 2. Use a shell script to achieve batch compression.
#下载批量压缩脚本
wget https://raw.githubusercontent.com/helloxz/shell/master/img_compress.sh
#执行shell脚本
bash img_compress.sh /home/wwwroot/blog.naibabiji.com/wp-content/uploads
In the above command, replace `/home/wwwroot/blog.naibabiji.com` with your own website directory path. The following `wp-content/uploads` corresponds to the WordPress uploads folder, where all our website's image attachments are located. The script is set by default to target files larger than 100k and modified within the last hour to avoid re-compressing images. You can edit the parameters in the script to set a longer time or remove the time restriction. The script was shared byXiao ZShare

Methods for Compressing Images in WordPress

The above method achieves automatic image compression by installing software on the server combined with a script (for full automation, it also needs to be paired with a scheduled task). So, if you are using WordPress hosting, how can you achieve automatic image compression? The methods are as follows:
  1. Install a batch image compression plugin. Well-known ones includeEWWW Image OptimizerSmushShortPixel Image Optimizeretc. Naibabiji usesCompress JPEG & PNG images
  2. Manually compress images locally before uploading them yourself;
  3. Enable WordPress's built-in image compression feature. Refer tothe article on optimizing WordPress image upload speed
  4. Use an image hosting or CDN service, which typically comes with automatic image compression features. Refer toWebsite images loading slowlythis article.

🚀 Still feeling confused after reading the tutorial? Let me guide you step-by-step.

「Naibabiji WordPress Website Building Coaching Service」—From choosing a domain and buying hosting, to installing a Theme and publishing content, I「ll coach you through every step, helping you avoid detours and reach your goal directly.

👉 Learn about the Website Building Coaching Service
🔒

Comments are closed

The comment function for this article is closed. If you have any questions, please feel free to contact us through other channels.

×
二维码

Scan QR Code to Follow

AI Website Building Assistant

🤖
Hello! I am the Naibabiji AI Assistant. How can I help you?
Quick Consultation: