Annotate is repeating on every image.

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
sirchuck
Posts: 6
Joined: 2019-05-21T19:26:44-07:00
Authentication code: 1152

Annotate is repeating on every image.

Post by sirchuck » 2019-05-21T19:36:01-07:00

Command Line Image:
I want 3 25x25 colored blocks, each block should contain a number.

convert -size 25x25 xc:#FFFFFF -gravity center -fill black -annotate +0 '1' -size 25x25 xc:#FFFFFF -gravity center -fill black -annotate +0 '2' -size 25x25 xc:#FFFFFF -gravity center -fill black -annotate +0 '3' +append capimg.png

That will produce 3 white blocks 25x25, the first block will have 1 2 and 3 annotated on it, the second block will have 2 and 3 annotated on it, and the third block will have the expected 3 annotated on it.

The blocks are white (FFFFFF) for example, in reality, I'll use different colors, but for simplicity, I'm using FFFFFF here.

I need the first and second block to only print 1 and 2 respectively without having other numbers written on top.

Thanks!

User avatar
fmw42
Posts: 25127
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Annotate is repeating on every image.

Post by fmw42 » 2019-05-21T19:45:53-07:00

You need to use parenthesis processing to keep each part separate.

Code: Select all

convert \
\( -size 25x25 xc:#FFFFFF -gravity center -fill black -annotate +0 '1' \) \
\( -size 25x25 xc:#FFFFFF -gravity center -fill black -annotate +0 '2' \) \
\( -size 25x25 xc:#FFFFFF -gravity center -fill black -annotate +0 '3' \) \
+append capimg.png
In Windows remove the \ from the parenthesis and replace the \ at the end of the lines with ^

See https://imagemagick.org/Usage/basics/#parenthesis

Please always provide your IM version and platform when asking questions. This avoid repeating of commands for Windows and Unix

User avatar
GeeMack
Posts: 701
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Annotate is repeating on every image.

Post by GeeMack » 2019-05-21T20:23:17-07:00

sirchuck wrote:
2019-05-21T19:36:01-07:00
The blocks are white (FFFFFF) for example, in reality, I'll use different colors, but for simplicity, I'm using FFFFFF here.

I need the first and second block to only print 1 and 2 respectively without having other numbers written on top.
When using "-annotate" you can include FX expressions within the text, and let the command increment the numbers for you. Here's an example...

Code: Select all

convert -size 25x25 xc:white xc:yellow xc:pink \
   -gravity center -pointsize 12 -annotate +0 %[fx:t+1] -scene 1 out%d.png
A command like this will create three squares, 25x25, of three different colors. Then it prints a number in the center of each, starting at "1" and incrementing to the total number of squares. In this case you'll have a white square with a "1", a yellow square with "2", and a pink square with "3". The output files will be named "out1.png", "out2.png", and "out3.png".

For Windows, replace the continued line backslash "\" with a caret "^".

If you're using IM version 7, use "magick" instead of "convert".

sirchuck
Posts: 6
Joined: 2019-05-21T19:26:44-07:00
Authentication code: 1152

Re: Annotate is repeating on every image.

Post by sirchuck » 2019-05-21T20:30:28-07:00

Yup, that was it, thanks.

Interestingly I wasn't able to put it on one line in my php code running on Ubuntu Linux like:

ecec('convert \( -size 25x25 xc:#FFFFFF -gravity center -fill black -annotate +0 \'1\' \) \( -size 25x25 xc:#FFFFFF -gravity center -fill black -annotate +0 \'2\' \) \( -size 25x25 xc:#FFFFFF -gravity center -fill black -annotate +0 \'3\' \) +append capimg.png');

I actually had to put it in several lines:
exec('convert \
\( -size 25x25 xc:#FFFFFF -gravity center -fill black -annotate +0 \'1\' \) \
\( -size 25x25 xc:#FFFFFF -gravity center -fill black -annotate +0 \'2\' \) \
\( -size 25x25 xc:#FFFFFF -gravity center -fill black -annotate +0 \'3\' \) \
+append capimg.png');

Taking out the end line slash didn't seem to make a difference. Though, it's possible I missed a slash.

Post Reply