Annotate with leading zeros?

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
rylander
Posts: 9
Joined: 2009-11-30T02:37:18-07:00
Authentication code: 8675309

Annotate with leading zeros?

Post by rylander » 2019-07-01T05:48:32-07:00

I'm creating a numbered image sequence using:
for i in `seq 001 300`
do convert -size 2048x1080 xc:none -font arial -fill black -pointsize 48 -annotate +100+100 $i output_$(printf %04d $i).png
done

This works well but I would like the annotation text to be 001, 002, etc. rather than 1,2,3,10,13,137.
How do I do that?

snibgo
Posts: 12030
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Annotate with leading zeros?

Post by snibgo » 2019-07-01T06:13:40-07:00

The obvious answer is: use the same trick in annotate as you use for the output filename.
snibgo's IM pages: im.snibgo.com

rylander
Posts: 9
Joined: 2009-11-30T02:37:18-07:00
Authentication code: 8675309

Re: Annotate with leading zeros?

Post by rylander » 2019-07-01T06:42:44-07:00

Obviously thank you.

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

Re: Annotate with leading zeros?

Post by GeeMack » 2019-07-01T07:29:39-07:00

rylander wrote:
2019-07-01T05:48:32-07:00
This works well but I would like the annotation text to be 001, 002, etc. rather than 1,2,3,10,13,137.
In many installations the "seq" command will take an argument so it will include the leading zeros in the output. On mine it's "-w". Maybe try something like this...

Code: Select all

... seq -w 1 300 ...

snibgo
Posts: 12030
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Annotate with leading zeros?

Post by snibgo » 2019-07-01T09:10:15-07:00

Good point, GeeMack. "seq" from Cygwin has "-w", automatically choosing the required number of leading zeros.

I can also...

Code: Select all

seq -f %06g 1 300
... to get six digits, so three or more leading zeros.
snibgo's IM pages: im.snibgo.com

Post Reply