note 106622 deleted from function.imagefilter by danbrown
| From: | danbrown@php.net | Date: | Tue, 29 Nov 2011 15:54:17 +0000 |
| Subject: | note 106622 deleted from function.imagefilter by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-184799@lists.php.net to get a copy of this message | ||
Note Submitter: live627 at gmail dot com
----
I had the same problem as mail at kavisiegel dot com , below, except that I needed to preserve the
alpha channel. Here's what I got:
<?php
function imagefilterhue($im, $r, $g ,$b)
{
$rgb = $r + $g + $b;
$col = array($r / $rgb, $b / $rgb, $g / $rgb);
$height = imagesy($im);
$width = imagesx($im);
for ($x = 0; $x < $width; $x++)
{
for ($y = 0; $y < $height; $y++)
{
$rgb = imagecolorat($im, $x, $y);
$colors = imagecolorsforindex($im, $rgb);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
$newR = $r * $col[0] + $g * $col[1] + $b * $col[2];
$newG = $r * $col[2] + $g * $col[0] + $b * $col[1];
$newB = $r * $col[1] + $g * $col[2] + $b * $col[0];
imagesetpixel($im, $x, $y, imagecolorallocatealpha($im, $newR, $newG, $newB,
$colors['alpha']));
}
}
}
?>