Batch watermarking using -tile

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
vmr
Posts: 7
Joined: 2015-04-06T04:07:42-07:00
Authentication code: 6789

Batch watermarking using -tile

Post by vmr »

Is it possible to do watermarking using morgify command.
Seems like it completely ignores -tile option

Example:

Code: Select all

mogrify input.jpg -tile WATERMARK_FILE.png -path ./out
This read WATERMARK_FILE.png but do not compose anything

Please, any suggestions ?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Batch watermarking using -tile

Post by snibgo »

I don't use mogrify, but "-tile filename" is a setting, not an operation. Settings merely modify operations. You haven't asked for an operation that can use tiling.
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: Batch watermarking using -tile

Post by fmw42 »

246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: Batch watermarking using -tile

Post by 246246 »

snibgo wrote:I don't use mogrify, but "-tile filename" is a setting, not an operation.
Hmm, but 'man mogrify' (or 'man convert') shows "-tile filename" is described as an image operator. Do you think it's a manual bug?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Batch watermarking using -tile

Post by snibgo »

I don't know mogrify, but that seems to be a documentation bug. On http://www.imagemagick.org/script/comma ... essing.php , "-tile" is listed as a setting. As far as I know, "-tile" never changes any image, but does affect the working of some operations that do, such as "-draw".
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: Batch watermarking using -tile

Post by fmw42 »

In the following, -tile seems to be an operator. See http://www.imagemagick.org/Usage/canvas/#tile where the first example is

Code: Select all

composite -tile tile_weave.gif -size 60x60  xc:none  tile_copy.gif
or

Code: Select all

convert -size 60x60 xc:none -tile tile_weave.gif tile_copy.gif

But I generally prefer to use the other tiling methods, that do not need to tile over an image.

Such as:

Code: Select all

convert -size 60x60 tile:bg.gif  tile_size.gif
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Batch watermarking using -tile

Post by snibgo »

Ah, yes, true, thanks. So "-tile" can be an operator in "composite". Can it also be an operator in "convert" or "mogrify"?
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: Batch watermarking using -tile

Post by fmw42 »

snibgo wrote:Ah, yes, true, thanks. So "-tile" can be an operator in "composite". Can it also be an operator in "convert" or "mogrify"?
I showed the convert equivalent above, which I presume works. I have not tried it in mogrify. In that form, I do not think it will work, because you have two images in the command line. The only way to have two images is if one is pre-prepared and used in -draw in the mogrify command line as per http://www.imagemagick.org/Usage/basics ... fy_compose.

But I am not sure what the OP is trying to generate in the sense of tiling and watermarking. If he can provide an example or explain better, that would help. Is he trying to create tiled textures the size of the input images or is he trying to fill a masked area or is he trying to composite a smaller tiled image onto a larger background image?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Batch watermarking using -tile

Post by fmw42 »

I tried the following:

Code: Select all

cd
cd desktop/test1
mogrify -path ../test2 -format png \
-size 300x300 tile:rose: -write mpr:rose_tile +delete \
-gravity center -draw 'image over 0,0 0,0 "mpr:rose_tile"' *
But it gave an abort trap.


So the only way I can see to do tiled watermark is to prepare the tiled image to a size larger than needed for any image (or the size needed, if it will be the same for all images) and do something like:

Code: Select all

cd
cd desktop
convert -size 800x600 tile:rose: -alpha on -channel alpha -evaluate set 50% +channel rose_tile.png
cd test1
mogrify -path ../test2 -format png \
-gravity center -draw 'image over 0,0 300x300 "../rose_tile.png"' *
Unfortunately, the result has the full logo.png filled with tiled rose rather than just a 300x300 region. So it looks like the tiled image needs to prepared to the exact size wanted, if a smaller water mark is needed than the full image size.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Batch watermarking using -tile

Post by snibgo »

fmw42 wrote:I showed the convert equivalent above, which I presume works.
It doesn't seem to work.

This works, tiling rose across 300x200:

Code: Select all

composite -tile rose: -size 300x200 xc:none q1.png
This doesn't work:

Code: Select all

convert -size 300x200 xc:none -tile rose: q2.png
q2.png is 300x200, transparent black. The command ignores "-tile rose:".


Perhaps the OP has a partially transparent watermark, and want to tile that over an entire image, such as wm.png.

Code: Select all

convert -size 50x20 -background None label:watermark wm.png

convert wizard: -alpha on ( +clone -tile wm.png -draw "color 0,0 reset" ) -composite wizwm.png
It's a bit clumsy. There may be a better method.
Image

To tile just a partial area:

Code: Select all

convert wizard: -alpha on ( -size 300x300 xc: -alpha on -tile wm.png -draw "color 0,0 reset" ) -composite wizwm2.png
snibgo's IM pages: im.snibgo.com
246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: Batch watermarking using -tile

Post by 246246 »

snibgo wrote:Ah, yes, true, thanks. So "-tile" can be an operator in "composite".
In man pages in composite, -tile is defined as image settings with no arguments.

So -tile would work in almost any place in composite, (although some are not recommended order and currently seems to work for backward compatibility.)

% composite -tile rose: -size 300x200 xc:none show: # This is recommended order.
% composite rose: -size 300x200 -tile xc:none show: # Still seems to work.
% composite rose: -size 300x200 xc:none -tile show: # Also seems to work.

% composite rose: -tile -size 300x200 xc:none show: # Not work.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Batch watermarking using -tile

Post by fmw42 »

So -tile would work in almost any place in composite
No! Order is important. The -tile should come right after composite and any multiple input images must be in the correct order for any compose setting.
246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: Batch watermarking using -tile

Post by 246246 »

fmw42 wrote:
So -tile would work in almost any place in composite
No! Order is important. The -tile should come right after composite and any multiple input images must be in the correct order for any compose setting.
My point is -tile takes no file argument in composite. So old IM allowed allowed some wrong order command. (Probably IM7 would no more allows to put -tile after first image, but would be allowed after other options in syntactic meaning.)

Code: Select all

SYNOPSIS
       composite  [  options ... ] change-file base-file [ mask-file ] output-image
vmr
Posts: 7
Joined: 2015-04-06T04:07:42-07:00
Authentication code: 6789

Re: Batch watermarking using -tile

Post by vmr »

Hi guys,
Sorry for late to the party, I have some problems and have no time.
I solved the task by separately preparing watermark tiled image by size equalent or bigger then destination images. Thank you fmw42 for the hint.

Code: Select all

:: prepare emty transparent image  with size %IMG_SIZE%
convert -size %IMG_SIZE% xc:none "%WATERMARK_BASE_FILE%"
:: tile watermark on it
composite -dissolve 30 -tile "%WATERMARK_FILE%" "%WATERMARK_BASE_FILE%" "%WATERMARK_TILED_FILE%"
:: resize images and draw watermark on each image
morgify -resize %IMG_SIZE% -gravity center -draw "image src-over 0,0 0,0 '%WATERMARK_FILE%'" -path "%DST_DIR%" "%SRC_MASK%" 
-----------------
Unfortunately its inpossible to do it by single step (via morgify). Although morgify accepts the -tile parameter it result to nothing. Probably its is a bug, because image to tile is read from disk but not used.
Post Reply