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.
Resize watermarking text as per Image resolution
-
- Posts: 15
- Joined: 2019-03-05T22:47:03-07:00
- Authentication code: 1152
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Resize watermarking text as per Image resolution
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.
For Window, remove the \s on the parenthesis
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
-
- Posts: 15
- Joined: 2019-03-05T22:47:03-07:00
- Authentication code: 1152
Re: Resize watermarking text as per Image resolution
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.
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.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Resize watermarking text as per Image resolution
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
-
- Posts: 15
- Joined: 2019-03-05T22:47:03-07:00
- Authentication code: 1152
Re: Resize watermarking text as per Image resolution
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
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
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Resize watermarking text as per Image resolution
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
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
-
- Posts: 15
- Joined: 2019-03-05T22:47:03-07:00
- Authentication code: 1152
Re: Resize watermarking text as per Image resolution
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?
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?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Resize watermarking text as per Image resolution
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.