Annotate pages with customized page number (Perl)

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
empiempi
Posts: 1
Joined: 2013-07-16T05:28:49-07:00
Authentication code: 6789

Annotate pages with customized page number (Perl)

Post by empiempi »

I'm using Perl. I have an ImageMagick object containing 16 pages. I'd like to annotate each page with a text string that derives from the page number. However, I don't want to use the page number straight (unmodified), I want to format it in a certain way. If I wanted to use the page number straight (unmodified), I could use a single Annotate command using the '%p' escape: $image->Annotate(text=>'%p'... ). However, if I want to format the page number first (which I can do in Perl), I don't know how to use a single Annotate command with my customized text. I tried to save my formatted text in text files called "label_1.txt", "label_2.txt", "label_3.txt"... etc and then read their contents using the "@" text file character: $image->Annotate(text=>'@label_%p.txt'... ). But it seems that "@" makes the rest of the line literal, i.e. the "%p" is no longer interpreted by Annotate as a page number. Is there a way to Annotate multiple pages with custom-formatted text? Thanks.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Annotate pages with customized page number (Perl)

Post by anthony »

'@' means read text from file literally. This is done so as to provide a 'literial source' for the text.
if you want the '@' backslash it '\@....'
if you want to do text substitutions like page numbers, either do it in the file before hand, on the command line, or in the API call, using percent escapes.

Hmmm... I am not certain if the perl API does percent escapes or not. I am not certain it even provides access to the InterpretImageProperties() function that does percent escape substitutions.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply