note 71181 rejected from ref.image by nicobn
| From: | nicobn@php.net | Date: | Sun, 01 Jul 2007 14:51:03 +0000 |
| Subject: | note 71181 rejected from ref.image by nicobn | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-128138@lists.php.net to get a copy of this message | ||
Note Submitter: jason at tectonic dot co dot za
----
function chromagradient(&$image, $startgradient, $endgradient, $chromacolor) {
$testcolor=imagecolorallocate($image,30,50,10);
$width=imagesx($image);
$height=imagesy($image);
$endindex=imagecolorsforindex($image,$endgradient);
$startindex=imagecolorsforindex($image,$startgradient);
$reddiff=$startindex['red']-$endindex['red'];
$greendiff=$startindex['green']-$endindex['green'];
$bluediff=$startindex['blue']-$endindex['blue'];
$found=false;
$y=0;
while ((!$found) && ($y<$height)) {
$x=0;
while(($x<$width) && (!$found)) {
$col=imagecolorat($image,$x,$y);
if ($col==$chromacolor) {
$startpoint=$y;
$found=true;
break;
}
$x++;
}
$y++;
}
$found=false;
$y=$height;
while ((!$found) && ($y>0)) {
for ($x=0;$x<$width;$x++) {
$col=imagecolorat($image,$x,$y);
if ($col==$chromacolor) {
$endpoint=$y;
$found=true;
break;
}
}
$y--;
}
$gheight=$endpoint-$startpoint;
for ($x=0;$x<$width;$x++) {
for ($y=$startpoint;$y<$endpoint;$y++) {
$newblue=$startindex['blue'] - floor(($y-$startpoint)*$bluediff/($gheight));
$newgreen=$startindex['green'] - floor(($y-$startpoint)*$greendiff/($gheight));
$newred=$startindex['red'] - floor(($y-$startpoint)*$reddiff/($gheight));
$replacementcol=imagecolorallocate($image, $newred, $newgreen, $newblue);
$col=imagecolorat($image,$x,$y);
if ($col==$chromacolor) {
imagesetpixel($image,$x,$y,$replacementcol);
}
}
}
}