Page 1 of 1

[SOLVED] Text Watermarking Problem with IM7

Posted: 2016-11-27T10:52:51-07:00
by kwash
I've being using text watermarking with IM for quite some time. But it seems that some recent IM7 code change is preventing me from getting the desired result. Now the text watermark image fails to be generated.

Here are the commands that I was using to generate a text watermark image with good results, which now fails:

Code: Select all

magick -size 250x80 xc:grey30 -font Arial -pointsize 28 -gravity center \
         -draw "fill gray70  text 0,0  'watermark'" \
         fgnd.png
magick -size 250x80 xc:black -font Arial -pointsize 28 -gravity center \
         -draw "fill white  text  1,1  'watermark'  \
                            text  0,0  'watermark'  \
                fill black  text -1,-1 'watermark'" \
         -alpha Off mask.png
magick fgnd.png mask.png -alpha Off -compose copy-opacity -composite watermark.png
magick mogrify -trim +repage watermark.png
The command that looks like to be causing the failure is:

Code: Select all

magick fgnd.png mask.png -alpha Off -compose copy-opacity -composite watermark.png
The result of the above composite/compose command is a white image with size of 1x1 and 259 bytes lenght, like a single white dot image.

Using:
ImageMagick: git master (currently at 7.0.3.9.r11361.g6e6ce01)
libpng: 1.6.26
OS: Arch Linux x86_64

It was working perfectly until some few IM7 versions ago. I've tested with IM 6.9.6.5 and the above commands works perfectly for generating the text watermark image after being translated to IM6 syntax. But I would like to continue using IM7.

Any help or comments would be appreciated.
Thank you.

Re: Text Watermarking Problem with IM7

Posted: 2016-11-27T12:42:06-07:00
by fmw42
First IM 7.0.3.9 is a beta and may be in a state of development where things are not worked out and bugs exist due to that.

In IM 7.0.3.8 Q16 Mac OSX Snowleopard it works fine for me.
(libpng 1.6.24)

Curious that you would use mogrify to trim one image, rather than convert. Also you could put all the commands into one convert to save from having temporaries.

Re: Text Watermarking Problem with IM7

Posted: 2016-11-27T17:13:22-07:00
by kwash
fmw42 wrote:First IM 7.0.3.9 is a beta and may be in a state of development where things are not worked out and bugs exist due to that.

In IM 7.0.3.8 Q16 Mac OSX Snowleopard it works fine for me.
(libpng 1.6.24)
Thanks, it works as usual with IM 7.0.3.8 Q32. I've being using the git master version for a long time and never had any major problem, so I thought it would be stable enough for daily use (and for reporting issues). From now on I'll try to switch to the release version to avoid such problems.
fmw42 wrote:Curious that you would use mogrify to trim one image, rather than convert. Also you could put all the commands into one convert to save from having temporaries.
These commands comes from the IM6 examples in IM website. I've being using it for a long time since IM6 and just adapted them for IM7 syntax. Could you please gently show how would be your solution?
Thanks.

Re: Text Watermarking Problem with IM7

Posted: 2016-11-27T18:29:33-07:00
by fmw42
It is no different for IM 6 or IM 7. See the parenthesis processing at http://www.imagemagick.org/Usage/basics/#parenthesis

Unix syntax:

Code: Select all

magick \
\( -size 250x80 xc:grey30 -font Arial -pointsize 28 -gravity center \
         -draw "fill gray70  text 0,0  'watermark'" \) \
\( -size 250x80 xc:black -font Arial -pointsize 28 -gravity center \
         -draw "fill white  text  1,1  'watermark'  \
                                   text  0,0  'watermark'  \
                    fill black  text -1,-1 'watermark'" \
         -alpha Off \) \
-alpha Off -compose copy-opacity -composite \
-trim +repage watermark.png
For windows, change \( ... \) to ( ... ) and change the line endings \ to ^

See http://www.imagemagick.org/Usage/windows/

Re: Text Watermarking Problem with IM7

Posted: 2016-11-27T19:41:23-07:00
by GeeMack
kwash wrote:
fmw42 wrote:Curious that you would use mogrify to trim one image, rather than convert. Also you could put all the commands into one convert to save from having temporaries.
These commands comes from the IM6 examples in IM website. I've being using it for a long time since IM6 and just adapted them for IM7 syntax. Could you please gently show how would be your solution?
I work mostly in Windows, so I rebuilt your command example with IM7 for Windows. ImageMagick can keep track of several (thousands in practice) images through an entire single command process. You're essentially using two for your purpose, so you can make them both and manipulate them as separate images in one command with no need to output them between steps. This should give you an idea of how to assemble these steps into a single command...

Code: Select all

magick -size 250x80 -font Arial -pointsize 28 -gravity center ^
   ( xc:grey30 -draw "fill gray70 text 0,0 'watermark'" ) ^
   ( xc:black -draw "fill white text 1,1 'watermark' text 0,0 'watermark'" ^
              -draw "fill black text -1,-1 'watermark'" ) ^
   -alpha off -compose copy-opacity -composite -trim +repage watermark.png
The canvas size, font, and pontsize settings only have to be given once since they remain the same from section to section. Then you build the first image, the equivalent of your "fgnd.png", inside a set of parentheses. Next you build the "mask.png" part inside another set of parentheses. Finish by setting the compose method, compositing the images, and naming the output file to create "watermark.png".

As fmw42 mentioned, the syntax would be slightly different running it from a *nix shell. The continued line character would be a backslash "\" instead of a caret "^", and all the parentheses "(...)" would have to be escaped with backslashes "\(...\)" because they have a special meaning in a *nix shell. You should have no difficulty applying the concept to suit your need.

Re: Text Watermarking Problem with IM7

Posted: 2016-11-28T18:55:58-07:00
by kwash
fmw42 wrote:It is no different for IM 6 or IM 7. See the parenthesis processing at http://www.imagemagick.org/Usage/basics/#parenthesis

Unix syntax:

Code: Select all

magick \
\( -size 250x80 xc:grey30 -font Arial -pointsize 28 -gravity center \
         -draw "fill gray70  text 0,0  'watermark'" \) \
\( -size 250x80 xc:black -font Arial -pointsize 28 -gravity center \
         -draw "fill white  text  1,1  'watermark'  \
                                   text  0,0  'watermark'  \
                    fill black  text -1,-1 'watermark'" \
         -alpha Off \) \
-alpha Off -compose copy-opacity -composite \
-trim +repage watermark.png
For windows, change \( ... \) to ( ... ) and change the line endings \ to ^

See http://www.imagemagick.org/Usage/windows/
Thanks for pointing this! It works perfectly.
I see that it also supports nested parenthesis.
GeeMack wrote:I work mostly in Windows, so I rebuilt your command example with IM7 for Windows. ImageMagick can keep track of several (thousands in practice) images through an entire single command process. You're essentially using two for your purpose, so you can make them both and manipulate them as separate images in one command with no need to output them between steps. This should give you an idea of how to assemble these steps into a single command...

Code: Select all

magick -size 250x80 -font Arial -pointsize 28 -gravity center ^
   ( xc:grey30 -draw "fill gray70 text 0,0 'watermark'" ) ^
   ( xc:black -draw "fill white text 1,1 'watermark' text 0,0 'watermark'" ^
              -draw "fill black text -1,-1 'watermark'" ) ^
   -alpha off -compose copy-opacity -composite -trim +repage watermark.png
The canvas size, font, and pontsize settings only have to be given once since they remain the same from section to section. Then you build the first image, the equivalent of your "fgnd.png", inside a set of parentheses. Next you build the "mask.png" part inside another set of parentheses. Finish by setting the compose method, compositing the images, and naming the output file to create "watermark.png".

As fmw42 mentioned, the syntax would be slightly different running it from a *nix shell. The continued line character would be a backslash "\" instead of a caret "^", and all the parentheses "(...)" would have to be escaped with backslashes "\(...\)" because they have a special meaning in a *nix shell. You should have no difficulty applying the concept to suit your need.
Thanks for all the explanation! It was really useful. And putting the common part outside the individual parenthesis was a nice point.
I successfully combined another command in order to apply the watermark to a given image.

All this talk was very appreciated. I started with a problem in IM git master, got it solved, and at the end was able to improve my scripts. Thank you fmw42 and GeeMack. :)