note 95983 deleted from function.imagecopymerge by danbrown
| From: | danbrown@php.net | Date: | Mon, 01 Feb 2010 15:31:31 +0000 |
| Subject: | note 95983 deleted from function.imagecopymerge by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-165569@lists.php.net to get a copy of this message | ||
Note Submitter: peterjwest3 at gmail dot com
----
Sina's method is elegant but had a small bug as well as some redundant code. Here is a more
concise version with better comments:
<?php
//PNG alpha channel support for imagecopymerge()
//This works because imagecopy() supports alpha but not blending, while imagecopymerge() supports
blending but not alpha
function imagecopymerge_alpha($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h,
$pct) {
//Creates a portion of the destination image and overlays the source image (with alpha)
$portion = imagecreatetruecolor($src_w, $src_h);
imagecopy($portion, $dst_im, 0, 0, $dst_x, $dst_y, $src_w, $src_h);
imagecopy($portion, $src_im, 0, 0, $src_x, $src_y, $src_w, $src_h);
//Blends the portion with the original image
imagecopymerge($dst_im, $portion, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct);
}
?>