Last active
November 11, 2022 21:13
-
-
Save jasperf/f1165adda96c386badb3 to your computer and use it in GitHub Desktop.
Optimize png, jpg images / Convert svgs to png #imagemagick #inkscape #png #optipng
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//inkscape from the command line conversion | |
cd your-directory-with-the-svgs/ | |
for i in *; do inkscape $i --export-png=`echo $i | sed -e 's/svg$/png/'`; done | |
//imagemagick | |
mogrify -format png *.svg | |
######png bash optimization one directory | |
#!/bin/bash | |
cd /path/to/png/storage/2010/01/c/ | |
mkdir optimized | |
## store optimized images in optimized directory ## | |
## Keep file system permission and make a backup of original PNG (see options below) ## | |
for i in *.png; do optipng -o5 -quiet -keep -preserve -dir optimized -log optipng.log "$i"; done | |
##########optipng all in one directory with find and xargs | |
cd /var/www/html/uploads/ | |
find . -type f -iname "*.png" -print0 | xargs -I {} -0 optipng -o5 -quiet -keep -preserve -log optipng.log "{}" | |
### optimizing jpgs | |
find /the/image/path -name "*.jpg" -type f -exec jpegtran -copy none -optimize -outfile {} {} \; |
As I found that gist in Google, I presume someone else will also. Here is lossless optimisation for your png and jpeg images:
find . -type f -iname "*.png" -exec optipng -o7 -preserve {} \;
find . -type f -iname "*.png" -exec advpng -z4 {} \;
find . -type f -iname "*.png" -exec pngcrush -rem allb -brute -reduce -ow {} \;
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -exec jpegoptim --strip-none {} \;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
optipng -o7 *.png for png compression / optimization