PDA

View Full Version : If possible lossless web image compression - image optimization ?



Fli
11-16-2014, 08:15 PM
Hello,

is there any way to compress website image (jpg, png. gif) the way it dont loose any quality but still is maximum compressed?
I want to optimise my website images, preferrably from linux command line

I tried to install Trimage (does png and jpg) but unsuccessfully on CentOS, it had many large dependencies to install:How to install Trimage on Linux? (http://internetlifeforum.com/linux-forums/2571-how-install-trimage-linux/)

Then i installed "JpegOptim" (does jpg, jpeg) (yum install jpegoptim or apt-get install jpegoptim) then lossless compress image .jpg ...
command "jpegoptim image.jpg"


image.jpg 250x250 24bit N Exiff XMP IPTC [OK] 53345 --> 53379 bytes (-0.06%), skipped.

So almost no reduction in that image case, if one want to really compress images (85% quality), then use: "jpegoptim -m85image.jpg".
For optimizing all .jpg images recursivelly:


find /home/myusername/public_html -type f -iname "*.jpg" -exec jpegoptim -m85 {} \;

Here is more detailed info about JPEG lossless optimization & compression: Compress JPG images losslessly into JPEG Progressive? (http://internetlifeforum.com/linux-forums/2568-compress-jpg-images-losslessly-into-jpeg-progressive/)

Then i installed OptiPNG (does .png) (yum install optipng or apt-get install optipng).
This is an example of almost lossless png optimization: (optipng -o0 image.png)
Good png compression while keeping quality practically same: (optipng -o2 image.png)
For optimizing all .png images recursivelly:


find /home/myusername/public_html -type f -iname "*.png" -exec optipng -o2 -preserve {} \; -exec chown OWNERUSERNAME:OWNERUSERNAME {} \;

(in case you are logged in as root and the website username is other, optipng will change file owner to root, so at the end we do chown)
Alternative to OptiPNG for lossless optimization can be "PngOut (http://www.laurencegellert.com/2013/06/compression-utility-pngout-a-free-lunch-bytes-are-on-the-menu/)"

Then i installed "GifSicle" (does .gif) (yum install gifsicle or apt-get install gifsicle)
Low loss gif optimization: gifsicle -b -O1 orig-animation.gif -o new-animation.gif
Bigger gif optimization: gifsicle -b -O2 orig-animation.gif -o new-animation.gif
If that command result in error "gifsicle: image.gif: not a GIF image", then try jpegoptim on it..

i did this command to optimize all .gif recursivelly:


find /home/myusername/public_html -type f -iname "*.gif" -exec gifsicle -b -O2 {} \;

-- SUMMARY: Trimage is not good for server use, its not in default repos. jpegoptim is in repos and optipng too. So i would use JpegOptim for jpg optimization/compression and OptiPng for png optimization/compression.


Need to bulk optimize several types of images on server recursivelly? Check this Linux shell script (http://internetlifeforum.com/programming-scripting/2577-linux-script-search-certain-file-types-do-speciffic-action-each-filetype/)

GridCash
03-24-2018, 06:40 PM
TinyPNG is a very good online tool for PNG compression