Optimize png and jpg files on your webserver to speed up your website and use less space…

Optimizing the images on your webserver can speed up your website and lower the space needed for them.

Please create a backup of your image files before you try to optimize them :)

I used optipng for png files and jpegoptim for jpeg files.

Optimizing png files

nice -n 20 find /path/to/images/ -iname "*png" -print0 | xargs --null optipng
** Processing: /path/to/wordpress/wp-content/uploads/2015/06/mdwiki_preview_files-300x205.png 300x205 pixels, 4x8 bits/pixel, RGB+alpha Input IDAT size = 33967 bytes Input file size = 34072 bytes Trying: zc = 9 zm = 8 zs = 0 f = 0 IDAT size = 25924 Selecting parameters: zc = 9 zm = 8 zs = 0 f = 0 IDAT size = 25924 Output IDAT size = 25924 bytes (8043 bytes decrease) Output file size = 25981 bytes (8091 bytes = 23.75% decrease)

Optimizing jpg files

nice -n 20 find /path/to/images/ -iname "*jpg" -print0 | xargs --null jpegoptim
/path/to/wordpress/wp-content/uploads/filename.jpg 600x400 24bit JFIF  [OK] 30238 --> 29575 bytes (2.19%), optimized. /path/to/wordpress/wp-content/uploads/filename2.jpg 1559x1012 24bit JFIF [OK] 281088 --> 260795 bytes (7.22%), optimized.

Fix permissions

Make sure to „give“ the files back to the webserver user if you did run the optimization as root or any other user…

chown -R www-data: /path/to/images/

My results…

The directory sizes contain the images and also all other files because I missed to count image files only :) If you compare only the images files before and after you get a much better ratio.

  • The whole Wordpress directory
    Before: 2454 MiB
    After: 2213 MiB
  • The whole DokuWiki directory
    Before: 1095 MiB
    After: 860 MiB

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.