Page 566 - Beginning PHP 5.3
P. 566
Part III: Using PHP in Practice
Here you ’ ve changed the imagecopy() function to imagecopymerge() and provided an opacity value
of 50 — halfway between transparent and opaque. The output of the script now looks a lot more like a
watermark, as Figure 17 - 20 shows.
Figure 17-20
If playing with transparency effects in images appeals to you, take a look at the imagecolorallo-
catealpha() and imagealphablending() functions in the PHP manual at http://www.php
.net/manual/en/ref.image.php . Although you won ’ t be able to reproduce all of the effects that
you can get with a professional graphics program, you can create some interesting effects nonetheless.
The next section also deals with manipulating an existing image, but this time you ’ re going to reduce it
to a thumbnail.
Creating Thumbnails
Creating a thumbnail of an image uses a similar method to applying a watermark, except that you copy
in the other direction — instead of copying the smaller image into the larger image, you copy the larger
image into a new smaller image, scaling it down as you go. Here ’ s an example script to create a
thumbnail:
< ?php
$mainImage = imagecreatefromjpeg( “lucky.jpg” );
528
9/21/09 2:48:45 PM
c17.indd 528 9/21/09 2:48:45 PM
c17.indd 528