What's wrong with transparency by GD?

E

Ela

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;
 
S

smallpond

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
 
E

Ela

"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?
 
S

smallpond

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top