Page 1 of 1
adding text to just one page of a multiple page TIFF
Posted: 2017-11-08T11:09:47-07:00
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!
Re: adding text to just one page of a multiple page TIFF
Posted: 2017-11-08T11:30:36-07:00
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
Re: adding text to just one page of a multiple page TIFF
Posted: 2017-11-08T11:40:31-07:00
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.
Re: adding text to just one page of a multiple page TIFF
Posted: 2017-11-08T12:34:47-07:00
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
Re: adding text to just one page of a multiple page TIFF
Posted: 2017-11-08T12:49:59-07:00
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
Re: adding text to just one page of a multiple page TIFF
Posted: 2017-11-08T12:56:11-07:00
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
Re: adding text to just one page of a multiple page TIFF
Posted: 2017-11-08T13:00:52-07:00
by ttuskey
Well that worked! Thank you very much.
I need to read up on -clone and -swap, it seems.
Again, my thanks.
Re: adding text to just one page of a multiple page TIFF
Posted: 2017-11-08T13:38:18-07:00
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.
Re: adding text to just one page of a multiple page TIFF
Posted: 2017-11-08T15:17:14-07:00
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.
Re: adding text to just one page of a multiple page TIFF
Posted: 2017-11-08T19:26:23-07:00
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