Skip to content

Instantly share code, notes, and snippets.

@cypres
Last active December 12, 2015 06:39
Show Gist options
  • Save cypres/4731210 to your computer and use it in GitHub Desktop.
Save cypres/4731210 to your computer and use it in GitHub Desktop.
Imagemagick conversions of vega images
# Find best replacement for Quality 60
find . -type f -name "*-ipad.jpg" -print0 | xargs -0 -n 1 identify -format "%f Q:%Q" | awk '/Q:60/ { H=substr($1,0,20); F=system("test -f " H "-fullscreen.jpg"); print F ? H ".jpg" : H "-fullscreen.jpg" }' > replacements.txt
# Generate the commands required for conversion
awk '{H=substr($1,0,20); print "convert " $1 " -quality 90 -profile sRGB.icm +profile '\''!iptc,!xmp,!icc,*'\'' -define jpeg:optimize-coding=on " H "-ipad.jpg" }' replacements.txt > replacement.sh
awk '{H=substr($1,0,20); print "cp " H "-ipad.jpg " H "[email protected]" }' replacements.txt >> replacement.sh
# Run the commands
chmod +x replacement.sh
sh replacement.sh
# Make a list of non-Quality-60 images
find . -type f -name "*-ipad.jpg" -print0 | xargs -0 -n 1 identify -format "%f Q:%Q" | grep -v "Q:60" | awk '{ H=substr($1,0,20); print H }' > remain.txt
# Make list of re-conversions with corrected colorprofile and less metadata (mogrify)
awk '{ print "mogrify -quality 90 -profile sRGB.icm +profile '\''!iptc,!xmp,!icc,*'\'' -define jpeg:optimize-coding=on " $1 "-ipad.jpg" }' remain.txt > highres.sh
awk '{ print "mogrify -quality 90 -profile sRGB.icm +profile '\''!iptc,!xmp,!icc,*'\'' -define jpeg:optimize-coding=on " $1 "[email protected]" }' remain.txt >> highres.sh
chmod +x highres.sh
sh highres.sh
# Thumbnails; re-convert with ICC conversion, and stripping metadata (mogrify)
find . -type f -name "*-ipad-thumb*.jpg" -print0 | xargs -t -0 -n 1 mogrify -quality 80 -profile sRGB.icm +profile '!iptc,*' -sampling-factor 2x2 -define jpeg:block-smoothing=on -define jpeg:optimize-coding=on
# Make new thumbnails for Quality 60
awk '{H=substr($1,0,20); print "convert " $1 " -gravity center " (length($1) == 24 ? "-extent 165x339" : "-resize 250x512^ -extent 250x512") " -quality 80 -profile sRGB.icm +profile '\''!iptc,*'\'' -define jpeg:block-smoothing=on -define jpeg:optimize-coding=on " H "-ipad-thumb.jpg" }' replacements.txt > newthumbs.sh
awk '{H=substr($1,0,20); print "convert " $1 " -gravity center -extent " (length($1) == 24 ? "165x339" : "283x580") " -quality 80 -profile sRGB.icm +profile '\''!iptc,*'\'' -define jpeg:block-smoothing=on -define jpeg:optimize-coding=on " H "[email protected]" }' replacements.txt >> newthumbs.sh
chmod +x newthumbs.sh
sh newthumbs.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment