the -annotate option is not parsing percent escapes

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
atariZen
Posts: 25
Joined: 2016-02-09T12:58:42-07:00
Authentication code: 1151

the -annotate option is not parsing percent escapes

Post by atariZen »

When -annotate is supplied a variable for the X offset, it ignores the whole coordinate. Yet it's able to do substitutions in the text message. E.g.

Code: Select all

convert magick:logo -set option:rt '%[fx:W/2-20]' \( -fill black -gravity center -annotate 90,90+%[rt]+0 "dimensions are %Wx%H and rt is %[rt]" \) -gravity east miff:- | display -
The %[rt] causes the argument to be ignored, so text string ends up in the middle of the image (it should be rotated 90 degrees and on the far right edge). If the X offset ("300") is hard-coded, then it does what it should:

Code: Select all

convert magick:logo -set option:rt '%[fx:W/2-20]' \( -fill black -gravity center -annotate  90,90+300+0 "dimensions are %Wx%H and rt is %[rt]" \) -gravity east miff:- | display -
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: the -annotate option is not parsing percent escapes

Post by fmw42 »

I do not believe that -annnotate offsets can be specified as a -set argument in IM 6. The text can be, however.

You can do this:

Code: Select all

convert logo: -set myinfo "+%[fx:w/2]+%[fx:h/2]" -fill black -gravity west -font arial -pointsize 36 -annotate +0+0 "%[myinfo]" show
But you cannot do this:

Code: Select all

convert logo: -set myinfo "+%[fx:w/2]+%[fx:h/2]" -fill black -gravity west -font arial -pointsize 36 -annotate "%[myinfo]" "%[myinfo]" show:
The same for -set option:myinfo

Similarly, when avoiding the -set and using the % calculations direction, this works:

Code: Select all

convert logo: -fill black -gravity west -font arial -pointsize 36 -annotate +0+0 "+%[fx:w/2]+%[fx:h/2]" show:
But this does not:

Code: Select all

convert logo: -fill black -gravity west -font arial -pointsize 36 -annotate "+%[fx:w/2]+%[fx:h/2]" "%wx%h" show:

But you can do these in IM 7, such as the following that does work.

Code: Select all

magick logo: -fill black -gravity northwest -font arial -pointsize 36 -annotate "+%[fx:w/8]+%[fx:h/2]" "%wx%h" show:
Post Reply