🚀 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-timebuild my own websiteusers may not know that images uploaded to a website need to be compressed in size, otherwise they will take up a lot of hard disk space over time. Naiba recently encountered several WordPress e-commerce websites where image attachments filled up the disk. Therefore, here is a guide on how to batch compress image sizes on a VPS with a Linux system.Prerequisites:This method is only forVPSIf you are usingWordPress hostingthen this method cannot be used.Specific Method:Here, we use the tools OptiPNG and jpegoptim along with a script to achieve automatic image 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, /home/wwwroot/blog.naibabiji.com should be replaced with your own website directory path. The following wp-content/uploads corresponds to the WordPress uploads folder, where all image attachments for our website are stored. The script is set by default to target files larger than 100k and modified within the last hour to avoid repeated compression. You can edit the parameters in the script to set a longer time or remove the time restriction. The script wasshared byLittle Z

Methods for Compressing WordPress Images

The above method achieves automatic image compression by installing software on the server and using a script (for full automation, it also needs to be combined with a scheduled task). So, if you are using WordPress hosting, how can you achieve automatic image compression? There are several methods:
  1. Install a batch image compression plugin. Popular ones includeEWWW Image OptimizerSmushShortPixel Image Optimizeretc. Naibabiji usesCompress JPEG & PNG images
  2. Manually compress images locally before uploading them;
  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 includes automatic image compression by default. Refer tothe article on slow website image loadingarticle.

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

「Naibabiji WordPress Website Building Coaching」 — From selecting a domain and purchasing hosting to installing themes and publishing posts, I「ll guide you through every step, helping you avoid detours and reach your goals directly.

👉 Learn about 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 to Follow