note 92787 modified in function.imagecopymerge by danbrown

From: Date: Sat, 08 Jan 2011 17:00:22 +0000
Subject: note 92787 modified in function.imagecopymerge by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-175537@lists.php.net to get a copy of this message
I've just checked PHP's issue tracker and a core developer says that this function was never meant to support alpha channel! and they refused to commit the provided patch! so ridicules Anyway i tried rodrigo's workaround and it worked quite well, thanks rodrigo for sharing it. I came up with another idea which is much faster than his solution, (it may need a little bit more memory) Hope it helps someone. <?php /** * PNG ALPHA CHANNEL SUPPORT for imagecopymerge(); * by Sina Salek * * Bugfix by Ralph Voigt (bug which causes it * to work only for $src_x = $src_y = 0. * Also, inverting opacity is not necessary.) * 08-JAN-2011 * **/ 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); } ?> --was-- I've just checked PHP's issue tracker and a core developer says that this function was never meant to support alpha channel! and they refused to commit the provided patch! so ridicules Anyway i tried rodrigo's workaround and it worked quite well, thanks rodrigo for sharing it. I came up with another idea which is much faster than his solution, (it may need a little bit more memory) Hope it helps someone. You can find me here : you can find me here http://sina.salek.ws/en/contact <?php /** * PNG ALPHA CHANNEL SUPPORT for imagecopymerge(); * This is a function like imagecopymerge but it handle alpha channel well!!! **/ function imagecopymerge_alpha($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct){ $opacity=$pct; // getting the watermark width $w = imagesx($src_im); // getting the watermark height $h = imagesy($src_im); // creating a cut resource $cut = imagecreatetruecolor($src_w, $src_h); // copying that section of the background to the cut imagecopy($cut, $dst_im, 0, 0, $dst_x, $dst_y, $src_w, $src_h); // inverting the opacity $opacity = 100 - $opacity; // placing the watermark now imagecopy($cut, $src_im, 0, 0, $src_x, $src_y, $src_w, $src_h); imagecopymerge($dst_im, $cut, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $opacity); } ?> http://php.net/manual/en/function.imagecopymerge.php

« previous php.notes (#175537) next »