note 107060 added to function.imagecopymerge
| From: | Leo at osu1 dot php dot net | Date: | Wed, 04 Jan 2012 14:27:38 +0000 |
| Subject: | note 107060 added to function.imagecopymerge | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-185353@lists.php.net to get a copy of this message | ||
imagecopymerge PHP function helped me to create a fast method that replaces one color by another in
true color images.
Beforehand for this purpose I had to loop over all the pixels of an image and replace color pixel by
pixel using imagecolorat and imagesetpixel; this method is really slow for large images.
So here is the fast one:
<?php
function replaceColorInImage ($image, $old_r, $old_g, $old_b, $new_r, $new_g, $new_b)
{
imagecolortransparent ($image, imagecolorallocate ($image, $old_r, $old_g, $old_b));
$w = imagesx ($image);
$h = imagesy ($image);
$resImage = imagecreatetruecolor ($w, $h);
imagefill ($resImage, 0, 0, imagecolorallocate ($resImage, $new_r, $new_g, $new_b));
imagecopymerge ($resImage, $image, 0, 0, 0, 0, $w, $h, 100);
return $resImage;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 141.228.106.147
----
Manual Page -- http://www.php.net/manual/en/function.imagecopymerge.php
Edit -- https://master.php.net/note/edit/107060
Del: integrated -- https://master.php.net/note/delete/107060/integrated
Del: useless -- https://master.php.net/note/delete/107060/useless
Del: bad code -- https://master.php.net/note/delete/107060/bad+code
Del: spam -- https://master.php.net/note/delete/107060/spam
Del: non-english -- https://master.php.net/note/delete/107060/non-english
Del: in docs -- https://master.php.net/note/delete/107060/in+docs
Del: other reasons-- https://master.php.net/note/delete/107060
Reject -- https://master.php.net/note/reject/107060
Search -- https://master.php.net/manage/user-notes.php