note 101741 deleted from function.imagecopymerge by danbrown
| From: | danbrown@php.net | Date: | Sat, 08 Jan 2011 17:00:38 +0000 |
| Subject: | note 101741 deleted from function.imagecopymerge by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-175538@lists.php.net to get a copy of this message | ||
Note Submitter: Ralph Voigt, php --at -- drakedata.com
----
Thanks to Sina Salek for the simplified imagecopymerge_alpha function with support for alpha
channel.
However, there's a bug which causes it to work only for $src_x = $src_y = 0.
Also, inverting opacity is not necessary.
Here's the fixed version:
<?php
/**
* PNG ALPHA CHANNEL SUPPORT for imagecopymerge();
* by Sina Salek
*
* Bugfix by Ralph Voigt
**/
function imagecopymerge_alpha($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h,
$pct){
// creating a cut resource
$cut = imagecreatetruecolor($src_w, $src_h);
// copying relevant section from background to the cut resource
imagecopy($cut, $dst_im, 0, 0, $dst_x, $dst_y, $src_w, $src_h);
// copying relevant section from watermark to the cut resource
imagecopy($cut, $src_im, 0, 0, $src_x, $src_y, $src_w, $src_h);
// insert cut resource to destination image
imagecopymerge($dst_im, $cut, $dst_x, $dst_y, 0, 0, $src_w, $src_h, $pct);
}
?>