Page 1 of 1
Resize watermarking text as per Image resolution
Posted: 2019-03-05T23:21:58-07:00
by aamir4774@gmail.com
Hi ImageMagick Community,
I'm working on watermarking the images using ImageMagick, there's a list of files that I possess with different formats(Tiff, jpeg, gif, bmp) and with different resolutions. Currently, I have specified a static text size but for the images with higher resolution the watermarked text seems to get diminished, is there a way to dynamically adjust the text size as per the image resolution in the output file.
Below is command that i'm passing through my java code to fetch images and write the watermarked images:
magick convert "D:\new_image_formats\<file_name>" -fill rgba(192,192,192,0.80) -font Arial -pointsize 60 -gravity center -annotate 315 "Copyright" "D:\ImageMagick\output\<file_name>"
Your help/suggestions will be highly appreciated.
Re: Resize watermarking text as per Image resolution
Posted: 2019-03-06T00:46:44-07:00
by fmw42
First in ImageMagick 7, use magick only, not magick convert.
Get the width of the image using -set option:wd "%w". Then create a new image of some percent of the width that you desire with transparent background and use label:"Copyright" to create a text image. Then composite that over your background image at the gravity and geometry offsets you desire. Here is an example in Unix syntax that will make the label 50% of the width of the image.
Code: Select all
magick lena.png -set option:wd "%[fx:0.5*w]" \( -background none -size "%[wd]x" -fill blue label:"Copyright" \) -gravity north -geometry +0+25 -compose over -composite result.png
For Window, remove the \s on the parenthesis
Re: Resize watermarking text as per Image resolution
Posted: 2019-03-08T02:53:49-07:00
by aamir4774@gmail.com
Hi fmw42,
Thanks for your quick reply. This query works for all the image file formats except for GIF images, it only gives a Still image (kind of distorted) of GIF without an watermark text on it. Can you please help me in availing it for GIFs as well.
Re: Resize watermarking text as per Image resolution
Posted: 2019-03-08T10:34:14-07:00
by fmw42
Is your GIF animated? If that is true, you need different processing
Code: Select all
magick lena.gif -coalesce -set option:wd "%[fx:0.5*w]" null: \( -background none -size "%[wd]x" -fill blue label:"Copyright" \) -gravity north -geometry +0+25 -compose over -layers composite -layers optimize result.gif
Re: Resize watermarking text as per Image resolution
Posted: 2019-03-11T13:31:54-07:00
by aamir4774@gmail.com
Hi fmw42,
Again, Thanks for your valuable help. Yes I'm trying to watermark animated gifs and was getting the error. Tried with the one which you posted in your recent reply and I was able to generate the watermark on GIFs, but I require to have this text placed diagonally with 50% opacity. Tried with the below command but was unsuccessful. Could you please rectify
Code: Select all
magick mygif_file1.gif -coalesce -set option:wd "%[fx:0.5*w]" null: \( -background transparent -size "%[wd]x" -stroke "#000b" -fill "#000a" label:"Copyright" -blur 3x3 -stroke none -fill "#ffff" label:"Copyright" -rotate "315" \) -gravity center -compose dissolve -define compose:args=50 -composite -quality 50 -geometry +0+25 -compose over -layers composite -layers optimize output.gif
Re: Resize watermarking text as per Image resolution
Posted: 2019-03-11T14:20:26-07:00
by fmw42
Just use transparent color for your label: For example from my previous example:
magick lena.gif -coalesce -set option:wd "%[fx:0.5*w]" \
null: \
\( -background none -size "%[wd]x" -fill "rgba(0,0,255,0.5)" label:"Copyright" -rotate -45 \) \
-gravity center -geometry +0+0 \
-compose over -layers composite -layers optimize \
result.gif
Re: Resize watermarking text as per Image resolution
Posted: 2019-03-12T14:16:06-07:00
by aamir4774@gmail.com
Hi fmw42,
Thanks for all your help, with the above command I was able to generate the watermark on Animated GIFs. Again Thanks for all your help.
Lastly, I had a query to ask, is there a way to generate watermarked images without writing back an output image. Basically, the requirement I mean to specify is I'll provide input to ImageMagick, process it for watermarking and instead of writing a new watermarked output file I wish to collect the watermarked image into an object of BufferedReader(which is capable of reading the char/byte array) of my Java class. Is there a possibility to bring this to effect?
Re: Resize watermarking text as per Image resolution
Posted: 2019-03-12T16:11:01-07:00
by fmw42
Sorry, I do not know the Java API. So I cannot answer that. You can pipe your output using GIF:- as the output. But I am not sure that is what you want.