note 113049 modified in function.imagefilter by kalle
| From: | kalle@php.net | Date: | Sat, 11 Jan 2014 06:33:17 +0000 |
| Subject: | note 113049 modified in function.imagefilter by kalle | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-198200@lists.php.net to get a copy of this message | ||
Here is an alternative to IMG_FILTER_COLORIZE filter, but taking the alpha parameter of each pixel
in account.
<?php
function rgba_colorize($img, $color)
{
imagesavealpha($img, true);
imagealphablending($img, true);
$img_x = imagesx($img);
$img_y = imagesy($img);
for ($x = 0; $x < $img_x; ++$x)
{
for ($y = 0; $y < $img_y; ++$y)
{
$rgba = imagecolorsforindex($img, imagecolorat($img, $x, $y));
$color_alpha = imagecolorallocatealpha($img, $color[0], $color[1], $color[2],
$rgba['alpha']);
imagesetpixel($img, $x, $y, $color_alpha);
imagecolordeallocate($img, $color_alpha);
}
}
}
?>
--was--
Here is an alternative to IMG_FILTER_COLORIZE filter, but taking the alpha parameter of each pixel
in account.
<?php
function rgba_colorize(&$img, $color)
{
imagesavealpha($img, true);
imagealphablending($img, true);
$img_x = imagesx($img);
$img_y = imagesy($img);
for ($x = 0; $x < $img_x; ++$x)
{
for ($y = 0; $y < $img_y; ++$y)
{
$rgba = imagecolorsforindex($img, imagecolorat($img, $x, $y));
$color_alpha = imagecolorallocatealpha($img, $color[0], $color[1], $color[2],
$rgba['alpha']);
imagesetpixel($img, $x, $y, $color_alpha);
imagecolordeallocate($img, $color_alpha);
}
}
}
?>
http://php.net/manual/en/function.imagefilter.php