-
Aug24
JPGs and PNGs losslessly by optimizing script
Filed under: World;No Comments
Currently I am going to clean up a bit in the blog and create some space on your webspace. Over the years has accumulated Some here so, where the “wp-content/uploads” folder makes all the uploaded images and thumbnails generated with the thickest chunks of 280MB. Many images offer the potential to be optimized with pngcrush and jpegtran lossless, but how to make over 8000 image files in many subdirectories automatically rattle through the tools?ViewIn principle one can save the expense if you installed from the house in WordPress plugin WP-Smush.it. This plugin sends all images uploaded to the blog after the first upload of the free image optimizer Smush.it by Yahoo!, so pictures of house, land optimizes the blog. Since the plugin I had not used a long time, I must now make some manual work.In a first step it takes you all “wp-content/uploads / ” folder via FTP to the plate. Depending on the setting for the library, the folder structure on you a little bit different, but I think that it is already at your pictures. Grabs the images after the best for a backup in an archive, so you have the option later to restore the thing, if you do not like the optimization should. Then installed the necessary programs …
$ Sudo apt-get install libjpeg-progs pngcrush
… and you throw the following script into the ~ / bin folder, I have the script with me in ~ / bin / directory smush. Please do not forget then the saved script on your favorite file manager, or $ chmod + x … to make it executable.
12345678910111213141516171819202122232425# / Bin / bashTMPFILE = $ (tempfile)jpegtran if type-P &>/ dev / null then;echo 'Running jpegtran';for JPG in $ (find $ 1-type f-name \ *. jpg);doecho “$ jpg crushing”;jpegtran-outfile $ TMPFILE-copy none-optimize-progressive “jpg $”;mv-f $ TMPFILE $ jpg;done;elseecho 'jpegtran not found';fi# Find files with a png extension and process recursively with pngcrushpngcrush if type-P &>/ dev / null then;for PNG in $ (find $ 1-type f-name \ *. png);doecho “crushing $ PNG”;pngcrush-brute “$ PNG” $ TMPFILE;mv-f $ TMPFILE $ PNG;done;elseecho 'pngcrush not found';fi# / Bin / bashTMPFILE = $jpegtran if type-P &>/ dev / null then;echo 'Running jpegtran';for JPG in $;doecho “$ jpg crushing”;jpegtran-outfile $ TMPFILE-copy none-optimize-progressive “jpg $”;mv-f $ TMPFILE $ jpg;done;elseecho 'jpegtran not found';fi# Find files with a png extension and process recursively with pngcrushpngcrush if type-P &>/ dev / null then;for PNG in $;doecho “crushing $ PNG”;pngcrush-brute “$ PNG” $ TMPFILE;mv-f $ TMPFILE $ PNG;done;elseecho 'pngcrush not found';fi
Then you can let the script on your pictures. Give it easy on the root folder, which you have previously downloaded. Before you start the script, I will still give to a “warning”, specifically takes you to optimize PNGs for quite a while. In my pictures folder with about 8000 images and more than 280MB, the act has on a computer with CPU Core i3 certainly needed more than two hours.
$ Smush ~ / foo / bar / uploads
Has been worth the effort? On average saves around 10% per image. The size of my pictures folder went from ~ 281MB down to about 260MB. The “low” income for me is probably because I had years ago been optimized once a part of the images. If you have never used WP-Smush.it or some other method to optimize should, then you probably get better results.
$ Du-s uploads281 264 uploads$ Du-s uploads_smush261 100 uploads_smushJust who
Verblogt many pictures should take care in any case, once by optimizing the graphics. The methods used in the script to reduce the file size without causing any loss of quality. Hence, the action is worthwhile in any case. Optimize away 10% of file size for images is: 10% less traffic in images and therefore – in relation to the images – 10% faster load time of the blog.
.
