note 96283 added to function.imagesetpixel
| From: | cyberhorse at users dot sourceforge dot net | Date: | Thu, 18 Feb 2010 15:54:29 +0000 |
| Subject: | note 96283 added to function.imagesetpixel | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-166151@lists.php.net to get a copy of this message | ||
Given an image $src and mask $mask, this applies the mask over the image, using different levels of
transparency properly.
<?php
function image_mask(&$src, &$mask) {
imagesavealpha($src, true);
imagealphablending($src, false);
// scan image pixels
for ($x = 0; $x < imagesx($src); $x++) {
for ($y = 0; $y < imagesy($src); $y++) {
$mask_pix = imagecolorat($mask,$x,$y);
$mask_pix_color = imagecolorsforindex($mask, $mask_pix);
if ($mask_pix_color['alpha'] < 127) {
$src_pix = imagecolorat($src,$x,$y);
$src_pix_array = imagecolorsforindex($src, $src_pix);
imagesetpixel($src, $x, $y, imagecolorallocatealpha($src, $src_pix_array['red'],
$src_pix_array['green'], $src_pix_array['blue'], 127 -
$mask_pix_color['alpha']));
}
}
}
}
?>
If your mask is reversed, change 127 - $mask_pix_color['alpha'] with just
$mask_pix_color['alpha']
----
Server IP: 117.55.229.1
Probable Submitter: 118.210.224.140
----
Manual Page -- http://www.php.net/manual/en/function.imagesetpixel.php
Edit -- https://master.php.net/note/edit/96283
Del: integrated -- https://master.php.net/note/delete/96283/integrated
Del: useless -- https://master.php.net/note/delete/96283/useless
Del: bad code -- https://master.php.net/note/delete/96283/bad+code
Del: spam -- https://master.php.net/note/delete/96283/spam
Del: non-english -- https://master.php.net/note/delete/96283/non-english
Del: in docs -- https://master.php.net/note/delete/96283/in+docs
Del: other reasons-- https://master.php.net/note/delete/96283
Reject -- https://master.php.net/note/reject/96283
Search -- https://master.php.net/manage/user-notes.php