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 »

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: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Annotate with leading zeros?

Post by snibgo »

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 »

Obviously thank you.
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Annotate with leading zeros?

Post by GeeMack »

rylander wrote: 2019-07-01T05:48:32-07:00This 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: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Annotate with leading zeros?

Post by snibgo »

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