note 82729 added to function.imagecolorset
| From: | ThomasMueller at osu1 dot php dot net | Date: | Wed, 23 Apr 2008 17:42:34 +0000 |
| Subject: | note 82729 added to function.imagecolorset | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-138706@lists.php.net to get a copy of this message | ||
Here is a function to colorize a picture gradient style.
All you have to do is to pass an img-object and an array of colors.
e.g.
$arr = array('#000000', '#990000', '#00FFFF', '#FFFFDD');
colorize ($img, $arr);
<?php
function colorize($imgdata, $palette)
{
imageTrueColorToPalette($imgdata,false,0xFF);
$l = count($palette)-1;
$i = imagecolorstotal($imgdata);
while ($i--)
{
list($r,$g,$b) = array_values(imageColorsForIndex($imgdata,$i));
$grayscale = ($r*.3 + $g*.59 +$b*.11) / 0xFF;
$pos = $l*$grayscale;
$perc = $pos-floor($pos);
$tbase = str_replace("#", '', $palette[$pos]);
$baseR = hexdec(substr($tbase,0,2));
$baseG = hexdec(substr($tbase,2,2));
$baseB = hexdec(substr($tbase,4,2));
$tmix = str_replace("#", '', $palette[$pos+1]);
$mixR = hexdec(substr($tmix,0,2));
$mixG = hexdec(substr($tmix,2,2));
$mixB = hexdec(substr($tmix,4,2));
$resR = $baseR+($mixR-$baseR)*$perc;
$resG = $baseG+($mixG-$baseG)*$perc;
$resB = $baseB+($mixB-$baseB)*$perc;
imagecolorset($imgdata, $i, $resR, $resG, $resB);
}
}
?>
----
Server IP: 217.13.201.10
Probable Submitter: 84.60.10.123
----
Manual Page -- http://www.php.net/manual/en/function.imagecolorset.php
Edit -- https://master.php.net/note/edit/82729
Del: integrated -- https://master.php.net/note/delete/82729/integrated
Del: useless -- https://master.php.net/note/delete/82729/useless
Del: bad code -- https://master.php.net/note/delete/82729/bad+code
Del: spam -- https://master.php.net/note/delete/82729/spam
Del: non-english -- https://master.php.net/note/delete/82729/non-english
Del: in docs -- https://master.php.net/note/delete/82729/in+docs
Del: other reasons-- https://master.php.net/note/delete/82729
Reject -- https://master.php.net/note/reject/82729
Search -- https://master.php.net/manage/user-notes.php