-
-
Save julianxhokaxhiu/c0a8e813eabf9d6d9873 to your computer and use it in GitHub Desktop.
#!/bin/bash | |
# Improved as per feedback from @pascal - https://gist.github.com/julianxhokaxhiu/c0a8e813eabf9d6d9873#gistcomment-3086462 | |
find . -type f -iname "*.png" -exec optipng -nb -nc {} \; | |
find . -type f -iname "*.png" -exec advpng -z4 {} \; | |
find . -type f -iname "*.png" -exec pngcrush -rem gAMA -rem alla -rem cHRM -rem iCCP -rem sRGB -rem time -ow {} \; | |
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -exec jpegoptim -f --strip-all {} \; |
Thanks for the script... I added a flag just to optimize newer images than last run in order to make it faster each run.
find . -type f -newer optimg.flag -iname "*.png" -exec optipng -nb -nc {} \;
find . -type f -newer optimg.flag -iname "*.png" -exec advpng -z4 {} \;
find . -type f -newer optimg.flag -iname "*.png" -exec pngcrush -rem gAMA -rem alla -rem cHRM -rem iCCP -rem sRGB -rem time -ow {} \;
find . -type f -newer optimg.flag \( -iname "*.jpg" -o -iname "*.jpeg" \) -exec jpegoptim -f --strip-all {} \;
touch optimg.flag
I wouldn't use optipng nor pngcrush, pngquant is far superior than either of those two combined.
https://pointlessramblings.com/posts/pngquant_vs_pngcrush_vs_optipng_vs_pngnq/
Oh, and instead of using \( -iname "*.jpg" -o -iname "*.jpeg" \)
.. you can simply just use -iregex .*\.jpe?g$
in place.
Improved script that actually runs even if file optimg.flag is not created yet.
Also ignores specific directories if needed
https://gist.github.com/pduchnovsky/9544ea3447b48c65c2412f7d5aef1f7a
Thanks for the nice scripts. Is there a way to run them multithreaded?
@pduchnovsky why are you using the -f flag in jpegoptim. For me it increases the size of the images if they have already been optimized better. Everything works much better without it.
@pduchnovsky why are you using the -f flag in jpegoptim. For me it increases the size of the images if they have already been optimized better. Everything works much better without it.
I mean, this was in original script so I re-used it, but I wonder it might have something to do with using progressive optimization as well as stripping all metadata, which possibly would not happen if it's not forced and the file is already smaller.
Basically ensures that all of your files are optimized the same way.
Basically ensures that all of your files are optimized the same way.
Yes that was the case, nevertheless as things move forward, if there's a better way to tweak this script, I'm open to update it. Let me know what needs to be updated, and I'll do accordingly :)
Thanks to everyone coming here and saying hi, I appreciate any feedback and I'm glad you find this useful. Most of the time I do create gists for myself as a reminder for the future, but I'm glad others find it useful too.
Unless you're using the AdvanceMame emulator to generate PNGs you can skip the advpng line. https://linux.die.net/man/1/advpng
Basically ensures that all of your files are optimized the same way.
Yes that was the case, nevertheless as things move forward, if there's a better way to tweak this script, I'm open to update it. Let me know what needs to be updated, and I'll do accordingly :)
Thanks to everyone coming here and saying hi, I appreciate any feedback and I'm glad you find this useful. Most of the time I do create gists for myself as a reminder for the future, but I'm glad others find it useful too.
You could just pop it in a regular repo and allow pull requests. Thanks for the scripts, BTW: very helpful.
Ah right, sorry forgot about it. I was lazy and just run a full search and replace.