note 107066 added to function.imagecopymerge
| From: | Leo at osu1 dot php dot net | Date: | Wed, 04 Jan 2012 17:14:53 +0000 |
| Subject: | note 107066 added to function.imagecopymerge | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-185359@lists.php.net to get a copy of this message | ||
The following function creates mask of a true color image for a given color. Beforehand for creating
an image mask I used to loop over all image pixels and check their color using imagecolorat and copy
if the color matches with imagesetpixel. This was very slow for large images, so the following code
improves the process.
<?php
function getOppositeColor ($color)
{
return (
( (255 - ($color >> 16) & 0xFF) << 16 ) +
( (255 - ($color >> 8 ) & 0xFF) << 8 ) +
( (255 - ($color ) & 0xFF) )
);
}
function createImageMask (&$image, $color)
{
$w = imagesx ($image);
$h = imagesy ($image);
$tmpImage = imagecreatetruecolor ($w, $h);
imagecopy ($tmpImage, $image, 0, 0, 0, 0, $w, $h);
imagefilter ($image, IMG_FILTER_NEGATE);
imagecolortransparent ($image, getOppositeColor ($color));
imagecopymerge ($tmpImage, $image, 0, 0, 0, 0, $w, $h, 50);
imagedestroy ($image);
$image = $tmpImage;
}
?>
So for example, if we have a photo and we specify color = (255, 0, 0), i.e. red, the result will be
image of the same size with red pixels everywhere the original photo was red and grey pixels
exerywhere else.
----
Server IP: 69.147.83.197
Probable Submitter: 141.228.106.150
----
Manual Page -- http://www.php.net/manual/en/function.imagecopymerge.php
Edit -- https://master.php.net/note/edit/107066
Del: integrated -- https://master.php.net/note/delete/107066/integrated
Del: useless -- https://master.php.net/note/delete/107066/useless
Del: bad code -- https://master.php.net/note/delete/107066/bad+code
Del: spam -- https://master.php.net/note/delete/107066/spam
Del: non-english -- https://master.php.net/note/delete/107066/non-english
Del: in docs -- https://master.php.net/note/delete/107066/in+docs
Del: other reasons-- https://master.php.net/note/delete/107066
Reject -- https://master.php.net/note/reject/107066
Search -- https://master.php.net/manage/user-notes.php