text watermark change sizes depending on image it's on

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
pommeverte
Posts: 10
Joined: 2013-03-19T10:57:40-07:00
Authentication code: 6789

text watermark change sizes depending on image it's on

Post by pommeverte »

Hi guys,

I'm hitting a bit of a wall. I need to add a text watermark to images, however I don't know the size of these images so I end up with tet that isn't the appropriate size (tiny) on some images.
The command I use is:

Code: Select all

convert 'in.tif'[0] -profile 'AdobeRGB1998.icc' -resize 6150400@\> -background white -flatten -gravity southeast -stroke '#000C' -strokewidth 2 -annotate 0 'this is a test' -stroke none -fill white -annotate 0 'this is a test' 'out.jpg'
Like I mentioned earlier, I need to find a way of resizing this watermark along with the image.

Thanks in advance for your help. I could probably resize the watermark using size $(convert etc...)x$(convert etc..) or something of the likes, but some images are really big and I would like to save computer ressources wherever possible
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: text watermark change sizes depending on image it's on

Post by fmw42 »

create an image of your text with transparent background by using label: to fit the image width. Then composite the text image over your background image.

See
http://www.imagemagick.org/Usage/text/#label_bestfit
http://www.imagemagick.org/Usage/layers/#convert
pommeverte
Posts: 10
Joined: 2013-03-19T10:57:40-07:00
Authentication code: 6789

Re: text watermark change sizes depending on image it's on

Post by pommeverte »

But I am resizing the background image using an area size, so how do I know what size to give my label?
I'd also rather not make a label the size of the original file if I could help it as it would be a waste of ressources. Given the amount of conversions our server has to make this is important for us
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: text watermark change sizes depending on image it's on

Post by fmw42 »

resize your background, get its size and then create and overlay the text image via label:

Unfortunately, that means multiple commands.

Or pre-compute the size of the resized image first, then create the label to that size and overlay. You will either know the resize width and/or height or know what percent factor you use. So either way, you can compute the width and/or height of the resized image ahead of time.

Otherwise, do everything at the full image size, overlay the text image and then resize.

I am not sure there is any other way.
pommeverte
Posts: 10
Joined: 2013-03-19T10:57:40-07:00
Authentication code: 6789

Re: text watermark change sizes depending on image it's on

Post by pommeverte »

Is there any way I could pipe the resized image and get it's resized height/width on the fly? If not I guess I'll have to compute height/width, I was kind of using area size to avoid it but hey.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: text watermark change sizes depending on image it's on

Post by fmw42 »

pommeverte wrote:Is there any way I could pipe the resized image and get it's resized height/width on the fly? If not I guess I'll have to compute height/width, I was kind of using area size to avoid it but hey.
I do not believe that is possible in IM 6. But later in IM 7 I think that will be more feasible.

Unless you are using -resize with @ for file size, you can easily pre-compute the resized image width and height
xeviousx
Posts: 1
Joined: 2013-12-03T13:47:33-07:00
Authentication code: 6789

Re: text watermark change sizes depending on image it's on

Post by xeviousx »

Resurrecting this post from the dead,

I have attempted to run this code on a windows machine with the latest IM but the dissolve does not work (the watermark is fully opaque)

the code i am using is

convert in.tif -size 1555x2560 xc:none -gravity center -fill grey -font Arial \
-pointsize 227.25 -annotate 300x300+0+0 "Testing" -background none \
-compose dissolve -define compose:args=30,100 -composite out.tif

what if anything is wrong?

If i create a png image with the below code and composite it in a seperate process then it works just fine but i would like to get it in one go.

convert -size 1555x2560 xc:none -gravity center -fill grey -font Arial \
-pointsize 227.25 -annotate 300x300+0+0 "Testing" -background none watermark.png

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

Re: text watermark change sizes depending on image it's on

Post by snibgo »

convert in.tif -size 1555x2560 xc:none -gravity center -fill grey -font Arial \
-pointsize 227.25 -annotate 300x300+0+0 "Testing" -background none \
-compose dissolve -define compose:args=30,100 -composite out.tif
Eek. That code will:

read in.tif
create a second image 1555x2560 with transparent background
annotate both images
dissolve them together.

You need parentheses, something like this:
convert in.tif \( -size 1555x2560 xc:none -gravity center -fill grey -font Arial \
-pointsize 227.25 -annotate 300x300+0+0 "Testing" \) -background none \
-compose dissolve -define compose:args=30,100 -composite out.tif
Now the annotate will only be done to the second image.
snibgo's IM pages: im.snibgo.com
Post Reply