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?
Then i installed "JpegOptim" (does jpg, jpeg) (yum install jpegoptim or apt-get install jpegoptim) then lossless compress image .jpg ...
command "jpegoptim image.jpg"
Code:
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:
Code:
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?
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:
Code:
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"
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:
Code:
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
Bookmarks