[SOLVED] Bad text watermarking with IM7

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
kwash
Posts: 17
Joined: 2016-04-30T20:47:29-07:00
Authentication code: 1151

[SOLVED] Bad text watermarking with IM7

Post by kwash »

I've being using text watermark with IM for quite some time following the website example and it always worked very well. But recently IM7 changed the text watermarking behavior by creating a bad effect. Now it is producing a non desirable background in the watermark like this:

Image

Commands used:

Code: Select all

magick -size 130x50 xc:grey10 -font Arial -pointsize 25 -gravity center \
          -draw "fill gray50  text 0,0  'watermark'" \
          tmpfile-fgnd.png
          
magick -size 130x50 xc:black -font Arial -pointsize 25 -gravity center \
        -draw "fill white  text  1,1  'watermark'  \
                           text  0,0  'watermark'  \
               fill black  text -1,-1 'watermark'" \
        -alpha Off tmpfile-mask.png
        
magick tmpfile-fgnd.png tmpfile-mask.png -compose copy-opacity -composite watermark.png

magick mogrify -trim +repage watermark.png

magick background.png watermark.png -compose dissolve -define compose:args=85% -gravity center -geometry +0+0 -composite background-watermarked.png
The result is the same when switching to a classic IM6-compatible command style:

Code: Select all

convert -size 130x50 xc:grey10 -font Arial -pointsize 25 -gravity center \
          -draw "fill gray50  text 0,0  'watermark'" \
          tmpfile-fgnd.png
          
convert -size 130x50 xc:black -font Arial -pointsize 25 -gravity center \
        -draw "fill white  text  1,1  'watermark'  \
                           text  0,0  'watermark'  \
               fill black  text -1,-1 'watermark'" \
        +matte tmpfile-mask.png
        
composite -compose CopyOpacity tmpfile-mask.png tmpfile-fgnd.png watermark.png

mogrify -trim +repage watermark.png

composite -dissolve 85% -gravity center -geometry +0+0 watermark.png background.png background-watermarked.png
This undesired result is due to the command:

Code: Select all

magick tmpfile-fgnd.png tmpfile-mask.png -compose copy-opacity -composite watermark.png
(or in classic IM6-compatible command style due to the command:)

Code: Select all

composite -compose CopyOpacity tmpfile-mask.png tmpfile-fgnd.png watermark.png
This is being caused by the following git commit: 6156c31f93eed74b7441d509d97ce257d231c02d.

After reverting this git commit the result comes back to the expected one, which should be:
Image

Using imagemagick git master version in Arch Linux x86_64.
Any help or comments would be appreciated.
Thank you.
Last edited by kwash on 2016-08-06T12:16:40-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Bad text watermarking with IM7

Post by fmw42 »

Your commands work fine for me on my Mac OSX snow leopard


Version: ImageMagick 7.0.2-6 Q16 x86_64 2016-08-01 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2016 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib cairo fftw fontconfig freetype gslib jbig jng jp2 jpeg lcms lqr ltdl lzma openexr png ps rsvg tiff webp x xml zlib


I get the very same result as your last image.

Note that properly, you should add -alpha off before -compose copy_opacity. But it works fine for me even without it.

What is your IM version and platform and version of libpng?
kwash
Posts: 17
Joined: 2016-04-30T20:47:29-07:00
Authentication code: 1151

Re: Bad text watermarking with IM7

Post by kwash »

Thank you fmw42 for the reply and support.

Adding '-alpha Off' before '-compose copy-opacity' fixed it.

It was working without it since a very, very long time. As the example in the website doesn't mention it (or the legacy '+matte' as in IM6) and the result suddenly changed after that commit, I thought it could be a bug. The website example uses '+matte' only in the initial 'convert' command. Maybe the example in the website should be updated?

I'm using IM7 Q32 HDRI version git master (currently at 7.0.2.8.r11135.gc1c7fb4) and libpng 1.6.23 in Arch Linux x86_64.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Bad text watermarking with IM7

Post by fmw42 »

matte is deprecated in IM 7 in favor of -alpha on/off. See http://imagemagick.org/script/porting.php#cli

see also http://www.imagemagick.org/Usage/compose/#copyopacity
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Bad text watermarking with IM7

Post by fmw42 »

IM 7 is more strict in syntax than IM 6.
kwash
Posts: 17
Joined: 2016-04-30T20:47:29-07:00
Authentication code: 1151

Re: Bad text watermarking with IM7

Post by kwash »

Yes, I know that 'matte' is deprecated. That's why I used '-alpha Off' in 'convert' command in IM7 syntax to replace '+matte'.

The website example is for IM6, so it uses '+matte'. But it doesn't use '+matte' (or '-alpha Off') before '-compose CopyOpacity' as you pointed, so I thought that maybe it should be updated.

Anyway, it's fixed for me. Thank you.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: [SOLVED] Bad text watermarking with IM7

Post by fmw42 »

That web site example has not been upgraded in a long while and is using the outdated composite command rather than the more flexible convert ... -composite.
Post Reply