Click here to get back home

What's wrong with transparency by GD?

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
What's wrong with transparency by GD? Ela 04-30-2008
Posted by Ela on April 30, 2008, 4:05 am
Please log in for more thread options
After testing different parameters, I'm still unable to obtain 2 transparent
circles. Could anybody tell me what's wrong in the following codes?

#!/usr/bin/perl
use GD;

$im = new GD::Image(550,450);
$white = $im->colorAllocate(255,255,255);
$black = $im->colorAllocate(0,0,0);
$red = $im->colorAllocateAlpha(255,0,0,119);
$blue = $im->colorAllocateAlpha(0,0,255,119);
$im->transparent($white);
$im->alphaBlending(1);
$im->setStyle($black);

$im->filledArc(460,380,95,75,0,360,$red);
$im->filledArc(500,380,95,75,0,360,$blue);

open(IMG, ">test.png");
binmode IMG;
print IMG $im->png;
close IMG;



Posted by smallpond on April 30, 2008, 10:11 am
Please log in for more thread options
> After testing different parameters, I'm still unable to obtain 2 transparent
> circles. Could anybody tell me what's wrong in the following codes?
>
> #!/usr/bin/perl
> use GD;
>
> $im = new GD::Image(550,450);
> $white = $im->colorAllocate(255,255,255);
> $black = $im->colorAllocate(0,0,0);
> $red = $im->colorAllocateAlpha(255,0,0,119);
> $blue = $im->colorAllocateAlpha(0,0,255,119);
> $im->transparent($white);
> $im->alphaBlending(1);
> $im->setStyle($black);
>
> $im->filledArc(460,380,95,75,0,360,$red);
> $im->filledArc(500,380,95,75,0,360,$blue);
>
> open(IMG, ">test.png");
> binmode IMG;
> print IMG $im->png;
> close IMG;

"Blending mode is not available when drawing on palette images."
You need to be in true color mode, the default is palette mode.
--S

Posted by Ela on April 30, 2008, 11:20 am
Please log in for more thread options
> "Blending mode is not available when drawing on palette images."
> You need to be in true color mode, the default is palette mode.
> --S

You're correct. But why does color mode change lead to background
blackening?



Posted by smallpond on April 30, 2008, 12:05 pm
Please log in for more thread options
> > "Blending mode is not available when drawing on palette images."
> > You need to be in true color mode, the default is palette mode.
> > --S
>
> You're correct. But why does color mode change lead to background
> blackening?

New questions should go in new threads.

You need to initialize the background.

# Draw a transparent background
$bkg = $im->colorAllocateAlpha(0,0,0,127);
$im->transparent($bkg);
$im->alphaBlending(0); # replace pixels
$im->filledRectangle(0,0,549,449,$bkg);

# Now draw with blending
$im->alphaBlending(1);

now draw your circles


Similar ThreadsPosted
GD - way to preserve PNG transparency? January 5, 2006, 2:51 am
what's wrong with @$ip? September 8, 2004, 1:28 pm
What's wrong October 24, 2006, 8:27 pm
cannot use CPAN, what is wrong? September 5, 2004, 3:59 am
Is my algorithm wrong? September 16, 2004, 4:43 pm
What's wrong with this program? January 5, 2005, 1:29 pm
What's wrong with this code ? April 9, 2005, 1:19 pm
what's wrong with April 3, 2006, 6:32 am
Re: What's wrong with my installation September 2, 2006, 6:14 pm
[2] SQL error .... Can anyone tell me what's going wrong please?? April 25, 2007, 7:51 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap