Optimize images jpg png CentOS

Tác giả: Dương Nguyễn Phú Cường
Ngày đăng: 4 năm trước


ou want to make your site faster ?  maybe it is then an idea to optimize and compress png or jpg images via your SSH Terminal. If you got a lots of images you can save many of bytes by just compress images without losing any quality and discrease your website page size. First we going to install jpegoptim  +  optipng
# yum install optipng # yum install jpegoptim
How works  optipng ?
optipng file
optipng [options] file
optipng [options] input.png

How works  optipng ?
jpegoptim file.jpeg
jpegoptim [options] file.jpeg
jpegoptim photo.jpeg
First we go check how fast is your website and what your page size is
-   Check your site on:   http://tools.pingdom.com/fpt/ -   SAMPLE:   1.87s  Load time /  2.3 MB  Page size -  Check where your most images are  e.g   /wp-content/  or /images/
Now we gonna start optimize  PNG & JPG/JPEG!
#  cd /home/user/domains/domain.com/public_html/wp-content/uploads/ # all images in current directory:  jpegoptim *.jpg # or  jpegoptim  */*.pg (all directories)   or 1 image:  jpegoptim image1.jpg # all images in current directory:  optipng *.png # or  optipng  */*.png (all directories)   or 1 image:  optipng image1.png
More information: http://freecode.com/projects/jpegoptim http://optipng.sourceforge.net/ find -type f -name "*.png" -exec optipng {} \; find -type f -name "*.jpg" -exec jpegoptim --strip-all {} \; find -type f -name "*.jpeg" -exec jpegoptim --strip-all {} \;  

JPG optimization

cd /path/to/your/image/folder
find . -iname "*.jp*" -print0 | xargs -0 jpegoptim --strip-all -m76

PNG optimization

cd /path/to/your/image/folder
find . -iname '*.png' -print0 | xargs -0 optipng -o7 -preserve