I have made a command that works with magick 7. It uses the new %[fx] and draw syntax
magick input.png \
-stroke black -strokewidth 3 \
-draw "line 0,0 20,0" \
-draw "line 0,0 0,20" \
-draw "line 0,%[fx:h] 20,%[fx:h]" \
-draw "line 0,%[fx:h] 0,%[fx:h-20]" \
-draw "line %[fx:w],0 %[fx:w-20],0" \
-draw "line %[fx:w],0 %[fx:w],20" \
-draw "line %[fx:w],%[fx:h] %[fx:w-20],%[fx:h]" \
-draw "line %[fx:w],%[fx:h] %[fx:w],%[fx:h-20]" \
output.png
Unfortunately it does not work for batch processing with magick mogrify
magick mogrify -stroke black -strokewidth 3 \
-draw "line 0,0 20,0" \
-draw "line 0,0 0,20" \
-draw "line 0,%[fx:h] 20,%[fx:h]" \
-draw "line 0,%[fx:h] 0,%[fx:h-20]" \
-draw "line %[fx:w],0 %[fx:w-20],0" \
-draw "line %[fx:w],0 %[fx:w],20" \
-draw "line %[fx:w],%[fx:h] %[fx:w-20],%[fx:h]" \
-draw "line %[fx:w],%[fx:h] %[fx:w],%[fx:h-20]" \
-- *.png
and gives an error
mogrify: non-conforming drawing primitive definition `%' @ error/draw.c/RenderMVGContent/4059.
I could use the v6 syntax but this does not seem like it should be necessary.
The issue is that mogrify in Imagemagick is old IM 6 structure and is just called when using IM 7 magick mogrify. It did not have all the upgrades put in to IM 7 magick. One of the big things in IM 7 magick is the ability to do fx computations inline. But it was not put into mogrify. You can create a number of variables for each fx: in separate commands and use the variables in your magick mogrify command to do the draw.
In Unix syntax, this would be: