The optimization of the compression of images is an important factor in speed of loading web pages. As I am in my period optimization, I sought a method to reduce the size of PNG.
Here are two absolutely essential tools:
Pngnq , to convert a PNG file with 256 colors by defining a color palette that best reflects the mood of the image.
Optipng him, several methods of compression tests to obtain a PNG image of an optimal size. It also removes all the useless information.
Then simply use the following commands to convert the image:
pngnq -vf -s1 image.png
optipng -o7 image-nq8.png
Note that pngnq saves the image as the image image.png-nq8.png. Finally, of course, if the reduction of color gives an image of very poor quality, we will use that optipng.
For example the image at the top of this article was originally 128kb and no longer than 33kb, yet the quality is correct.
For Linux users, I made a small bash program to automate the commands:
#!/bin/bash
pngnq -vf -s1 $1.png
optipng -o7 $1-nq8.png
echo " Conversion Terminée !"
To use, enter the command. / Png.sh picture or "image" is the name of the image without the extension and png.sh the name of the file where I enter the script.
For installation on Linux (Debian, Ubuntu):
sudo apt-get install pngnq optipng
These programs are also available for Windows:





















9 users commented on this post
This works well when I'm in the directory that contains images.
If I give a path (including the sh) I get errors like what he can not play the file.
Otherwise it works, but the gain is not great, I passed a file of more than 800k to 245ko and 229.8 kb
I am looking for the path problem.
I just tried, it works:
For an image named "test.png" and placed in / home / username / Pictures, simply enter the following command:
. / Png.sh / home / username / Images / image
That, and sorry again for the response time, I'm very busy right now!
+ +
Etan
Here is the batch script to automate the conversion in Windows (to put in a file png.bat):
@ Echo off
pngnq-vf-s1 "% 1.png"
optipng-o7 "% 1-nq8.png"
echo Completed Conversion
And is used as follows: png.bat nom_de_l_image
(Still without extension name)
I compared the utilities to optimize PNG images, and it turns out that the best is the one found here: http://www.css-ig.net/scriptpng
on the same site, there are lots of information to optimize the quality and size of images!
Thank you for the info, this utility looks very effective!
I'll do some testing ;-)
Along the same lines I did a tutorial on that allows pngcrush to compress png lossless is what yahoo uses it to Smush. If you feel like it: http://dev.petitchevalroux.net.....x.344.html
Thank you for sharing! I did not know this technique.
A test!
Pingback and Trackback
Leave a Comment