List Info

Thread: Watermark opacity problem




Watermark opacity problem
country flaguser name
United States
2008-05-17 02:20:26
Hello,

   I would like to watermark images using the Perl
Graphics::Magick module.

   My watermark image is a simple ring, which I have saved
as a 24-bit PNG
using Photoshop. The non-ring areas are transparent.

   My image to be watermarked is a greyscale JPG.

   The problem is that when I composite them together the
result is not the
ring on the image. The transparent areas of the PNG become
incorrectly opaque,
so instead of a ring the result is a box with a ring. The
box is the problem.
I do not want to see the watermark image bounding box.

   I have packed the files and script for download:

http://acatysmoof.com/posting/problems/gm_opacity.tgz

   Use the test.pl script to watermark any image with the
test_wm.png file
like this:

   ./test.pl test.jpg

   The result will be test_watermarked.jpg, which shows the
incorrect results.

   I'm using version 1.2.1 on FreeBSD 4.10. Any ideas
greatly appreciated.

Thanks,
Alex

------------------------------------------------------------
-------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Graphicsmagick-help mailing list
Graphicsmagick-helplists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gra
phicsmagick-help

Re: Watermark opacity problem
country flaguser name
United States
2008-05-17 12:25:41
>
>   Use the test.pl script to watermark any image with
the test_wm.png file
> like this:
>
>   ./test.pl test.jpg
>
>   The result will be test_watermarked.jpg, which shows
the incorrect results.

The problem is that the Composite 'opacity' value is wrong. 
The value 
is an absolute value based on the range of a quantum rather
than a 
percentage of range.  A value of 25 is almost completely
opaque.

With your example, I achieve good results if I use

   opacity => 65535*0.25

The PerlMagick test suite uses this ugly code in order to
determine 
the depth of the PerlMagick build:

$QuantumDepth=quantumDepth();
if ($QuantumDepth == 8)
   {
     $MaxRGB=255;
   }
elsif ($QuantumDepth == 16)
   {
     $MaxRGB=65535;
   }
elsif ($QuantumDepth == 32)
   {
     $MaxRGB=4294967295;
   }

Bob
======================================
Bob Friesenhahn
bfriesensimple.dallas.tx.us, http://w
ww.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer,    http://www.GraphicsMag
ick.org/


------------------------------------------------------------
-------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Graphicsmagick-help mailing list
Graphicsmagick-helplists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gra
phicsmagick-help

Re: Watermark opacity problem
country flaguser name
United States
2008-05-17 22:26:21
On Sat, 17 May 2008 12:25:41 -0500 (CDT), Bob Friesenhahn
wrote
> A value of 25 is almost completely opaque.

Hi Bob,

   Thats strange. My result with my original settings:

   ${$r_img}->Composite(
                         image   => $wm,
                         compose => 'Dissolve',
                         opacity => 25,
                         gravity => 'Center',
                       );

   is this:

http://acatysmoof.com/posting/problems/gm/test_opaci
ty25.jpg


> 
> With your example, I achieve good results if I use
> 
>    opacity => 65535*0.25
> 

My result with these settings:

   ${$r_img}->Composite(
                         image   => $wm,
                         compose => 'Dissolve',
                         opacity => 65535*0.25,
                         gravity => 'Center',
                       );

is this:

http://acatysmoof.com/posting/problems/gm/tes
t_opacity65535_025.jpg

yikes!

The result I'm looking for (created manually in Photoshop)
is this:

http://acatysmoof.com/posting/problems/gm/
test_opacity25_photoshop.jpg


I'm starting to think you may be getting different results
than I am, or that
there is mabye a small snippet of code that was also
modified that I'm
missing? Perhaps there is an external library issue in this
operation? Any
further help very much appreciated.


> The PerlMagick test suite uses this ugly code in order
to determine 
> the depth of the PerlMagick build:
> 
> $QuantumDepth=quantumDepth();
> if ($QuantumDepth == 8)
>    {
>      $MaxRGB=255;
>    }
> elsif ($QuantumDepth == 16)
>    {
>      $MaxRGB=65535;
>    }
> elsif ($QuantumDepth == 32)
>    {
>      $MaxRGB=4294967295;
>    }

I reserve ternary alternation for exactly these types of
ugly perl moments 

my $maxrgb = $quantumdepth == 8  ? 255        :
             $quantumdepth == 16 ? 65535      :
             $quantumdepth == 32 ? 4294967295 :
             die "bad quantum depth";

Thanks,
Alex

------------------------------------------------------------
-------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Graphicsmagick-help mailing list
Graphicsmagick-helplists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gra
phicsmagick-help

Re: Watermark opacity problem
country flaguser name
United States
2008-05-18 01:15:30
On Sun, 18 May 2008 00:34:02 -0500 (CDT), Bob Friesenhahn
wrote
> I produced the attached image like:
> 
> gm composite -gravity center -dissolve 25 watermark.png
base.jpg 
> -depth 8 output.png
> 
> That proves that at least the underlying software
works.  The issue 
> is either with the implementation of PerlMagick, or how
to use it.

Hi Bob,

   That commandline works for me too. I'll dig around in the
PerlMagick guts
too, but from what I remember it requires XS - which isn't
my strong suit (or
even my weak suit).

   Thanks again for helping out with this.

Thanks,
Alex

------------------------------------------------------------
-------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Graphicsmagick-help mailing list
Graphicsmagick-helplists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gra
phicsmagick-help

Re: Watermark opacity problem
country flaguser name
United States
2008-05-18 00:34:02
On Sat, 17 May 2008, Alex Teslik wrote:
>
> I'm starting to think you may be getting different
results than I am, or that
> there is mabye a small snippet of code that was also
modified that I'm
> missing? Perhaps there is an external library issue in
this operation? Any
> further help very much appreciated.

I am starting to wonder what I was smoking earlier since I
thought I 
saw an image similar to the one attached (probably stripped
on the 
list) but now I don't.

I produced the attached image like:

gm composite -gravity center -dissolve 25 watermark.png
base.jpg -depth 8 output.png

That proves that at least the underlying software works. 
The issue is 
either with the implementation of PerlMagick, or how to use
it.

> I reserve ternary alternation for exactly these types
of ugly perl moments 
>
> my $maxrgb = $quantumdepth == 8  ? 255        :
>             $quantumdepth == 16 ? 65535      :
>             $quantumdepth == 32 ? 4294967295 :
>             die "bad quantum depth";

I am sure that you are a far better Perl programmer than I
am now.  I 
am more than rusty. 

I will research this issue some more tomorrow.

Bob
======================================
Bob Friesenhahn
bfriesensimple.dallas.tx.us, http://w
ww.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer,    http://www.GraphicsMag
ick.org/

------------------------------------------------------------
-------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Graphicsmagick-help mailing list
Graphicsmagick-helplists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gra
phicsmagick-help

View Original Image
[1-5]

about | contact  Other archives ( Real Estate discussion Medical topics )