Adding Drop Shadows with PHP - Overlay the Original
(Page 6 of 7 )
The final step is to overlay the original image and send the results back to the requesting browser.
The imagecopymerge function can be used to copy a section of one image onto another.
<?php $original_image = imagecreatefromjpeg($src); imagecopymerge($image, $original_image, 0,0, 0,0, $o_width, $o_height, 100); ?> |
The imagecopymerge function accepts the base image, the overlay image, coordinates where to place the overlay on the base image, cropping coordinates for the overlaid section and an alpha transparency.
The overlaid image should be positioned at the top left of the base image. Since the entire original image will be superimposed, it's cropped coordinates should be 0,0 to its width and height. The image should be fully opaque so a value of 100 should be passed for the alpha.
The final results can then be sent to the browser using imagejpeg.
<?php header("Content-type: image/jpeg"); imagejpeg($image, "", 100); ?> |
By sending a Content-Type header, we are creating a PHP script that outputs the jpeg file directly to the browser.
The imagejpeg function can either save the image to a file or send the image directly to the request. By specifying an empty string for the file name it knows we wish to output the image directly to the browser. You can also set the compression quality of the image, which I have set at 100.
Once the image has been sent it's good practice to free up the resources we've consumed to generate it.
<?php imagedestroy($image); imagedestroy($original_image); ?> |
Next: Combined Code >>
More Miscellaneous Articles
More By bluephoenix