watermark just 2nd page of tiff and keeping both pages

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
arepea
Posts: 5
Joined: 2013-08-25T14:45:05-07:00
Authentication code: 6789

watermark just 2nd page of tiff and keeping both pages

Post by arepea »

I have been unable to figure out a DOS command line to
take a 2 page tiff
put a watermark on just the 2nd page of the tiff (annotate would be fine too)
save resulting tiff with both pages , preferably as a 'Save As' to replace the original tiff.

We have many tiffs to process each day, so batching is how we need to go. Can be bat, vbscript , jscript, wscript, cscript, powershell.
At one point I got the only 2nd page to change but the saved file contained just the one page.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: watermark just 2nd page of tiff and keeping both pages

Post by fmw42 »

You need to separate the pages and process the second and put it back with the first page.

convert image.tiff ( -clone 1 add-your-watermark-or-text \) -delete 1 image.tiff

The image.tiff has two layers or pages (numbered from 0) that IM will read when calling image.tiff -- page 0 and page 1. The parenthesis says make a copy of page 1 (the second page) and do whatever you need to add a watermark or text. Then delete the original page 1. Then write out the two pages back to your original image name.

The command would be different if you have more than two pages and need to watermark only one of the pages. You would need to know which page to watermark and to extract that page and substitute it back in the same order with the other pages.

I would recommend that you temporarily use a new output name, say image1.tiff until you work out the kinks of your watermark process.

One of the Windows users can probably give you more information about making this into a batch (.bat) file.

Watermarking can be added with an image by composition in side the parenthesis -- see http://www.imagemagick.org/Usage/compose/#watermark

or text can be added either directly using -annotate (or -draw) or by making a new text image with transparent background and composing that over the second page within the parenthesis --- see
http://www.imagemagick.org/Usage/text/
http://www.imagemagick.org/Usage/basics/#parenthesis


If you need further help, please identify your version of IM and provide some links to your input tiff and information about how you would want to create the watermark.
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: watermark just 2nd page of tiff and keeping both pages

Post by GreenKoopa »

On Windows, parenthesis don't need escaping with backslashes.
http://www.imagemagick.org/Usage/windows/#conversion

Alternatively to operating on the second image/page, Fred's command could be changed to watermark the last page.
http://www.imagemagick.org/Usage/basics/#list_ops
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: watermark just 2nd page of tiff and keeping both pages

Post by snibgo »

The only difference for Windows is that neither parenthesis should generally be escaped (in Unix, with backslash), thus:

Code: Select all

convert image.tiff ( -clone 1 add-your-watermark-or-text ) -delete 1 image.tiff
The exception is that within a Windows "if () else ()", parentheses may need to be escaped, with caret for Windows, ie "^(" and "^)".

If you have many files, you can put this inside a loop, eg a FOR loop in Windows batch.

You should think about your workflow. If you watermark the original files, you don't want to re-watermark them the same day, or the next day. Writing watermarked files to a different directory may be better.
snibgo's IM pages: im.snibgo.com
arepea
Posts: 5
Joined: 2013-08-25T14:45:05-07:00
Authentication code: 6789

Re: watermark just 2nd page of tiff and keeping both pages

Post by arepea »

Thanks for the replies, I didn't expect them so quickly so had not turned on the tiff pc :) .
I was hoping that one of the scripting languages would be able to call an object reference to the 2nd page, but if not doable then batch file it is.
I need the files to keep their names as they will be referenced and used by another program which requires the files to be in a certain directory.
So I think what i might do is move the tiffs to a working directory and then have the batch file do something like

Code: Select all

convert  %1 ( -clone 1 composite  -watermark 30% -gravity North c:\wip\Watermark.gif %1 %2\%1  ) -delete 1 %1
The source file name and destination directory would be passed in on the command line.

hmm, the tiffs are 240dpi b&w and the addition is a static 3 lines of text longest line 70 characters - is watermark best way to do or would draw or caption be better?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: watermark just 2nd page of tiff and keeping both pages

Post by snibgo »

For a scripting language like COM or perl or PHP, see the appropriate forum in index.php

If you want the text to be readable, this isn't really a watermark. Watermarks are generally designed to be hardly visible at all.

See http://www.imagemagick.org/Usage/text/ for lots of possibilities.
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: watermark just 2nd page of tiff and keeping both pages

Post by fmw42 »

convert %1 ( -clone 1 composite -watermark 30% -gravity North c:\wip\Watermark.gif %1 %2\%1 ) -delete 1 %1
You cannot call composite or another convert within a convert command. You will need to use the convert syntax.

see
http://www.imagemagick.org/Usage/compose/#watermark

convert image.tiff ^
( -clone 1 watermark.gif -compose modulate -define compose:args={brigthness}[,{saturation}] -composite ) ^
-delete 1 image.tiff

Also in windows, % needs to be escaped as %%.

see
http://www.imagemagick.org/Usage/windows/
arepea
Posts: 5
Joined: 2013-08-25T14:45:05-07:00
Authentication code: 6789

Re: watermark just 2nd page of tiff and keeping both pages

Post by arepea »

snibgo wrote: If you want the text to be readable, this isn't really a watermark. Watermarks are generally designed to be hardly visible at all.
See http://www.imagemagick.org/Usage/text/ for lots of possibilities.
using ImageMagick-6.8.6-9 . So I should use

Code: Select all

convert %1 ( -clone 1 composite -label:@c:\wip\Text2Show.txt -gravity North  %1 %2\%1 ) -delete 1 %1
? I don't have access to the pc right now, but that doesn't seem quite correct. ( using " http://www.imagemagick.org/Usage/annota ... mark_image , Composited Label: " as guide)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: watermark just 2nd page of tiff and keeping both pages

Post by fmw42 »

convert %1 ( -clone 1 composite -label:@c:\wip\Text2Show.txt -gravity North %1 %2\%1 ) -delete 1 %1
See my post above. You cannot put composite in a convert command nor another convert. Also it is not -label: but just label:

convert image.tiff ^
( -clone 1 -background none -fill somecolor -font somefont -pointsize somepointsize label:@c:\wip\Text2Show.txt ) ^
-gravity North -geometry +X+Y -compose over -composite -delete 1 image.tiff

see the links I posted above as well
arepea
Posts: 5
Joined: 2013-08-25T14:45:05-07:00
Authentication code: 6789

Re: watermark just 2nd page of tiff and keeping both pages

Post by arepea »

fmw42 wrote:
convert %1 ( -clone 1 composite -label:@c:\wip\Text2Show.txt -gravity North %1 %2\%1 ) -delete 1 %1
See my post above. You cannot put composite in a convert command nor another convert. Also it is not -label: but just label:

convert image.tiff ^
( -clone 1 -background none -fill somecolor -font somefont -pointsize somepointsize label:@c:\wip\Text2Show.txt ) ^
-gravity North -geometry +X+Y -compose over -composite -delete 1 image.tiff

see the links I posted above as well
So it would be " label:" and not "-label:" but "-composite" and not " composite" . okaaay. Thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: watermark just 2nd page of tiff and keeping both pages

Post by fmw42 »

arepea wrote:
fmw42 wrote:
convert %1 ( -clone 1 composite -label:@c:\wip\Text2Show.txt -gravity North %1 %2\%1 ) -delete 1 %1
See my post above. You cannot put composite in a convert command nor another convert. Also it is not -label: but just label:

convert image.tiff ^
( -clone 1 -background none -fill somecolor -font somefont -pointsize somepointsize label:@c:\wip\Text2Show.txt ) ^
-gravity North -geometry +X+Y -compose over -composite -delete 1 image.tiff

see the links I posted above as well
So it would be " label:" and not "-label:" but "-composite" and not " composite" . okaaay. Thanks.

Not quite, note the blue

convert image.tiff ^
( -clone 1 -background none -fill somecolor -font somefont -pointsize somepointsize label:@c:\wip\Text2Show.txt ) ^
-gravity North -geometry +X+Y -compose over -composite -delete 1 image.tiff

see
http://www.imagemagick.org/Usage/text/#label
http://www.imagemagick.org/Usage/layers/#convert
arepea
Posts: 5
Joined: 2013-08-25T14:45:05-07:00
Authentication code: 6789

Re: watermark just 2nd page of tiff and keeping both pages

Post by arepea »

fmw42 wrote:
arepea wrote: So it would be " label:" and not "-label:" but "-composite" and not " composite" . okaaay. Thanks.
Not quite, note the blue
convert image.tiff ^
( -clone 1 -background none -fill somecolor -font somefont -pointsize somepointsize label:@c:\wip\Text2Show.txt ) ^
-gravity North -geometry +X+Y -compose over -composite -delete 1 image.tiff

see
http://www.imagemagick.org/Usage/text/#label
http://www.imagemagick.org/Usage/layers/#convert
I think I understand what you are saying, but it is a moot point. This is running on a W03Server pc and fonts do not work under Windows (even though convert -list font will list all the fonts, font as a parameter will not work). So it is back to trying to figure out how to use watermark. I used the following:

Code: Select all

convert testme.0fb ( -clone 1 virtual-stamp.tif -compose modulate -define compose:args=75%,75% -composite ) -delete 1 image.tiff
which resulted in an error display of
convert.exe: Unknown field with tag 292 (0x124) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/824.
BUT , I got my tiff :)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: watermark just 2nd page of tiff and keeping both pages

Post by fmw42 »

That is just a warning that the Tiff file has meta data that IM does not understand. It will not prevent the processing.


If you have trouble with fonts, then instead of giving it a font name, use path2font/fontfile where typically the suffix will be .ttf

Note the argument is -font fontname or -font path2font/fontfile

be sure you use -font and not font.
Post Reply