Skip to content

Instantly share code, notes, and snippets.

@raspi
Last active March 21, 2023 23:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raspi/d8f628317fbc02bcf2f68bae05d7b6ca to your computer and use it in GitHub Desktop.
Save raspi/d8f628317fbc02bcf2f68bae05d7b6ca to your computer and use it in GitHub Desktop.
Output JSON from ImageMagick magick identify command
#!/bin/bash -e
# Output JSON from ImageMagick magick identify command
if [[ $# -eq 0 ]] ; then
echo "Usage:"
echo " $0 <filename>"
echo ""
exit 0
fi
FORMAT='{"filesize": "%[size]", "format": "%m", "height": %h, "width": %w, "compression_type": "%C", "compression": %Q}'
magick identify -precision 0 -format "$FORMAT" $1 | perl -pe 's@"filesize": "([^\"]+)B"@"filesize": \1@g'
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment