Home Experience & Tips Sharing Standard Post

Standard Post

Method for Batch Compressing WordPress Images on Linux VPS

Friends who are building a website for the first time may not know that images uploaded to the website need to be compressed in size, otherwise they will take up 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 I share how to batch compress image sizes on a Linux VPS. Prerequisite: This method is only for...

Updated on April 20, 2021 About 3 minutes reading
Linux VPS批量压缩WordPress图片的方法

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 OptiPNG and jpegoptim tools along with scripts to automatically compress image sizes.

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 system. If you are using Debian, Ubuntu, or other systems, please search for the corresponding command yourself.

2. Use shell script to batch compress

#下载批量压缩脚本
wget https://raw.githubusercontent.com/helloxz/shell/master/img_compress.sh
#执行shell脚本
bash img_compress.sh /home/wwwroot/blog.naibabiji.comhttps://edgeone.naibabiji.com/wp-content/uploads

In the above command, replace /home/wwwroot/blog.naibabiji.com with your own website directory path.

The wp-content/uploads folder corresponds to WordPress's upload folder, where our website's image attachments are stored.

The script defaults to processing files larger than 100k and modified within 1 hour to avoid repeated compression. You can edit the parameters in the script to set a longer time or remove the time limit.

The script is provided byXiao ZShare

Methods for Compressing Images in WordPress

The above method achieves automatic image compression by installing software on the server and using a script (fully automatic requires a scheduled task). So, if you are using a WordPress host, how do you achieve automatic image compression?

Here are several methods:

  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.
5/5 - (1 vote)
Previous Shopify vs WordPress: Which is Better for an E-commerce Platform, and What are the Differences? Continue reading content around the same timeline. Next Share 3 Premium Genuine WordPress Themes from Themeforest: Rabbit/Essential/Sigma View the next related tutorial or experience.

AI Website Building Assistant

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