[ prog / sol / mona ]

prog


What are you working on?

181 2022-05-01 10:52

A bit of trivia. The Ubuntu LTS ImageMagick generates broken json for crops:

$ import -version
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org
[...]
$ import -window root json:- | jq -r '.image.properties.signature'
aea4b9ef1793d5de84b184bba32d48088aa544765cf095fa1d9d760057d7be13
$ import -window root -crop 100x100+100+0 json:- | jq -r '.image.properties.signature'
parse error: Invalid numeric literal at line 96, column 0

That's because "originGeometry" lacks quotes and a comma:

$ import -window root -crop 100x100+100+0 json:- | cat -n | grep -E -e '^ *96\b' -C 4
    92	      "x": 100,
    93	      "y": 0
    94	    },
    95	    "originGeometry": +100+0
    96	    "dispose": "Undefined",
    97	    "iterations": 0,
    98	    "compression": "Undefined",
    99	    "quality": 85,
   100	    "orientation": "Undefined",

The quotes and comma have to be added externally:

$ import -window root -crop 100x100+100+0 json:- | gawk '($1 == "\"originGeometry\":") && ($2 ~ /^[0-9+x-]+$/) { $2 = "\"" $2 "\","; print; next } { print }' | jq -r '.image.properties.signature'
c5c4f9b6b4cfd1b225e45b534c82d3aa9ac5a4197724978a83e7b2f85825461e

The json is also broken for crop sequences:

$ import -window root png:- | convert - \( -clone 0 -crop 100x100+100+0 \) \( -clone 0 -crop 100x100+200+0 \) -delete 0 json:- | gawk '($1 == "\"originGeometry\":") && ($2 ~ /^[0-9+x-]+$/) { $2 = "\"" $2 "\","; print; next } { print }' | jq -r '.image.properties.signature'
parse error: Expected separator between values at line 99, column 12

This time the scene numbers lack commas:

$ import -window root png:- | convert - \( -clone 0 -crop 100x100+100+0 \) \( -clone 0 -crop 100x100+200+0 \) -delete 0 json:- | gawk '($1 == "\"originGeometry\":") && ($2 ~ /^[0-9+x-]+$/) { $2 = "\"" $2 "\","; print; next } { print }' | cat -n | grep -E -e '^ *99\b' -C 4
    95	"originGeometry": "+100+0",
    96	    "dispose": "Undefined",
    97	    "iterations": 0,
    98	    "scene": 0
    99	    "scenes": 2
   100	    "compression": "Zip",
   101	    "orientation": "Undefined",
   102	    "properties": {
   103	      "date:create": "...",

The commas have to be added externally:

$ import -window root png:- | convert - \( -clone 0 -crop 100x100+100+0 \) \( -clone 0 -crop 100x100+200+0 \) -delete 0 json:- | gawk '($1 == "\"originGeometry\":") && ($2 ~ /^[0-9+x-]+$/) { $2 = "\"" $2 "\","; print; next } ($1 ~ /^"scenes?":$/) && ($2 ~ /^[0-9]+$/) { $2 = $2 ","; print; next } { print }' | jq -r '.image.properties.signature'
2fa879782976a6c97019cf3214c165d21f6e977f1e8bbceee02e6a95335aaf0b
b4ef38259a67996958b320749eab1f591a91f950d4c89cde7554ca85c022d895

After this the json appears usable.

199


VIP:

do not edit these