Page 565 - Beginning PHP 5.3
P. 565
Chapter 17: Generating Images with PHP
Figure 17-19
Working with Opacity
The opacity of an image defines how transparent or opaque the image ’ s pixels are. An image can range
from completely see - through or transparent, to opaque, where you cannot see through the image at all.
In the imagecopy() function in the previous section, the black text of the copyright message was
opaque, and its white background was transparent.
To make the watermark less obvious, you can use the imagecopymerge() function to give the copied
image a degree of transparency. The function works in the exact same way as the imagecopy() function,
except that you also provide a ninth parameter, which controls how transparent or opaque the copied
image is. A value of zero means that the copied image is completely transparent and you won ’ t see it in
the final image, whereas a value of 100 means that the copied image is completely opaque — in which
case the function operates like the imagecopy() function. So you can simply change this line in the
watermark.php script:
imagecopy( $myImage, $myCopyright, $destX, $destY, 0, 0, $srcWidth,
$srcHeight );
to read:
imagecopymerge( $myImage, $myCopyright, $destX, $destY, 0, 0, $srcWidth,
$srcHeight, 50 );
527
9/21/09 2:48:44 PM
c17.indd 527
c17.indd 527 9/21/09 2:48:44 PM