barnabas at kendall dot NOSPAM dot net
12-Oct-2001 08:56
If you are trying to copy a transparant image on to another image, you
might assume that you should apply the ImageAlphaBlending function to the
image that has the transparancy, the source image. In reality, you must
apply the ImageAlphaBlending function to the destination image. Basically
it's saying, "make the specified image respect
transparancy".
Here's a real world example. Suppose you want
to put your logo on the upper left corner of a photograph. Your logo is a
PNG with transparancy, and the photo is a JPEG. Here's what you would
do:
<?php
$photoImage =
ImageCreateFromJPEG('photo.jpg');
ImageAlphaBlending($photoImage,
true);
$logoImage = ImageCreateFromPNG('logo.png');
$logoW =
ImageSX($logoImage);
$logoH =
ImageSY($logoImage);
ImageCopy($photoImage, $logoImage, 0, 0, 0,
0, $logoW, $logoH);
ImageJPEG($photoImage); // output to
browser
ImageDestroy($photoImage);
ImageDestroy($logoImage);
?>