adding text to just one page of a multiple page TIFF

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
ttuskey
Posts: 4
Joined: 2017-11-08T11:05:11-07:00
Authentication code: 1152

adding text to just one page of a multiple page TIFF

Post by ttuskey »

Hello!
I have this command down to do 99% of what I need.
magick convert image1.tif +swap -gravity northwest -annotate +150+275 "new text added" output.tif

image1.tif is a multiple page tiff with four pages. The above command is putting the text at the exact spot I want, but unfortunately on all four pages.
Is there a way to get it to only place the text on the FIRST page?

Thanks you!
ttuskey
Posts: 4
Joined: 2017-11-08T11:05:11-07:00
Authentication code: 1152

Re: adding text to just one page of a multiple page TIFF

Post by ttuskey »

I'd like to add that the command:
magick identify image1.tif
shows four pages, image1.tif[0] .. image1.tif[3].

If I repeat my original command with [0] appended to the name of the file, I get this error:
convert: no such image 'image1.tif' @error/mogrify.c/mogrifyImageList/8786
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: adding text to just one page of a multiple page TIFF

Post by snibgo »

What version of IM, on what platform?

"-annotate", like most image operations, operates on all the images in the current list. When you want to operate on only one image, start a new list with "(", clone the one you want, give your operation, and close that list with ")". Then you have all the original images, plus one with your annotation, so swap it and delete one.

"image1.tif[0]" should work. Please show your exact command.
snibgo's IM pages: im.snibgo.com
ttuskey
Posts: 4
Joined: 2017-11-08T11:05:11-07:00
Authentication code: 1152

Re: adding text to just one page of a multiple page TIFF

Post by ttuskey »

(running this on a Windows 7 PC, version=7.-.7-10 q16)
Thank you. Could you elaborate on this: " When you want to operate on only one image, start a new list with "(", clone the one you want, give your operation, and close that list with ")".

Sorry, I'm brand spanking new with imagemagick, and this is the first operation I'm trying with it. The reason I downloaded it.
If there's a better way to do this than annotate please point me in that direction.


Here's the output of the identify command
L:\Leader\leaderImages>magick identify image1.tif
image1.tif[0] TIFF 1728x2156 1728x2156+0+0 1-bit Bilevel Gray 97199B 0.000u 0:00.001
image1.tif[1] TIFF 1728x2156 1728x2156+0+0 1-bit Bilevel Gray 97199B 0.000u 0:00.001
image1.tif[2] TIFF 1728x2156 1728x2156+0+0 1-bit Bilevel Gray 97199B 0.000u 0:00.001
image1.tif[3] TIFF 1728x2156 1728x2156+0+0 1-bit Bilevel Gray 97199B 0.000u 0:00.001

Then for the actual annotate:
L:\Leader\leaderImages>magick convert image1.tif[0] +swap -gravity northwest -annotate +150+275 "2017TR000345" image2.tif
convert: no such image 'image1.tif' @ error/mogrify.c/MogrifyImageList/8786
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: adding text to just one page of a multiple page TIFF

Post by snibgo »

Like this:

Code: Select all

magick ^
image1.tif ^
( -clone 0 -gravity northwest  -annotate +150+275 "new text added" ) ^
-swap 0,4 +delete ^
out.tiff
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: adding text to just one page of a multiple page TIFF

Post by fmw42 »

In IM 7, you should only use magick, not magick convert. For other tools you need to preface them with magick, such as magick identify.

For annotating the first page of a multipage tiff, you can do the following (Windows syntax):

Code: Select all

magick image.tif ( -clone 0 -gravity northwest -annotate +150+275 "new text added" ) -swap 0,-1 +delete newimage.tif
The first page (image) in the command line sequence is numbered at 0 and the last image in the sequence is indicated by -1 no matter how many it is. So it saves you from having to count. IM know that the tiff is multipage and converts it into individual images automatically. So if you have 4 pages, there are 4 images in the command line sequence. So I clone the first page of the tiff as index 0 and annotate on it. That now makes a new 5th image in the sequence at the end after your original 4. So I swap the 0 index image (your original first page) with the new one. That puts the new one at 0 and the old one at 5 (or -1). So I delete the last one using +delete (rather than -delete). The +delete is always the last one. Then I create a new tif image from the remaining 4 images in the sequence.

Note you may want to specify your font and point size for the annotate and font color (fill color)

See
http://www.imagemagick.org/Usage/basics/#parenthesis
http://www.imagemagick.org/Usage/basics/#list_ops
http://www.imagemagick.org/Usage/basics/#clone
http://www.imagemagick.org/Usage/basics/#delete
http://www.imagemagick.org/Usage/text/#annotate

OOPS! Sorry snibgo, we must have been composing at the same time
ttuskey
Posts: 4
Joined: 2017-11-08T11:05:11-07:00
Authentication code: 1152

Re: adding text to just one page of a multiple page TIFF

Post by ttuskey »

Well that worked! Thank you very much.
I need to read up on -clone and -swap, it seems.

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

Re: adding text to just one page of a multiple page TIFF

Post by GeeMack »

ttuskey wrote: 2017-11-08T11:09:47-07:00image1.tif is a multiple page tiff with four pages. The above command is putting the text at the exact spot I want, but unfortunately on all four pages.
Is there a way to get it to only place the text on the FIRST page?
I don't want to muddy the waters here because snibgo and fmw42 have provided excellent responses already, but here's an idea how IM7 can do operations based on conditions, in this case the page number.

Code: Select all

magick input.tif -gravity northwest ^
   -annotate +%[fx:t==0?150:w*2]+%[fx:t==0?275:h*2] "your text here" out.tif
That reads the input TIFF, sets the gravity, and annotates every page. It annotates the first page "t==0" with an offset of "+150+275". Any page that is not "t==0" gets annotated with offsets of "+(w*2)" and "+(h*2)", that's twice the page width and twice the height, a location well outside the bounds of the page. Other than the first page, the annotations just disappear.

Using inline FX expressions will let you select several pages to annotate, or maybe annotate various pages at different locations. If this sort of thing might suit your needs for a more complex project, you can find out more about inline FX expressions at THIS link.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: adding text to just one page of a multiple page TIFF

Post by snibgo »

As always, brilliant out-of-the-box thinking from GeeMack.

In this particular case, a quick test shows the "-annotate +%[fx:t==0?150:w*2]+%[fx:t==0?275:h*2]" takes 50% longer, and the difference is greater with more images. I suppose IM laboriously rasterises text for each of the images, not realising the text will "miss" all but one of the images.
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: adding text to just one page of a multiple page TIFF

Post by anthony »

Gif Animation Modifications is a good away to see how to handle multiple pages

http://www.imagemagick.org/Usage/anim_mods/#frame_mod
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply