note 73213 added to function.substr
| From: | persisteus at web dot de | Date: | Tue, 13 Feb 2007 15:45:39 +0000 |
| Subject: | note 73213 added to function.substr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-123324@lists.php.net to get a copy of this message | ||
Here is also a nice (but a bit slow) alternative for colorizing an true color image:
// $colorize = hexadecimal code in String format, f.e. "10ffa2"
// $im = the image that have to be computed
$red = hexdec(substr($colorize, 0, 2));
$green = hexdec(substr($colorize, 2, 2));
$blue = hexdec(substr($colorize, 4, 2));
$lum_c = floor(($red*299 + $green*587 + $blue*144) / 1000);
for ($i = 0; $i < $lum_c; $i++)
{
$r = $red * $i / $lum_c;
$g = $green * $i / $lum_c;
$b = $blue * $i / $lum_c;
$pal[$i] = $r<<16 | $g<<8 | $b;
}
$pal[$lum_c] = $red<<16 | $green<<8 | $blue;
for ($i = $lum_c+1; $i < 255; $i++)
{
$r = $red + (255-$red) * ($i-$lum_c) / (255-$lum_c);
$g = $green + (255-$green) * ($i-$lum_c) / (255-$lum_c);
$b = $blue + (255-$blue) * ($i-$lum_c) / (255-$lum_c);
$pal[$i] = $r<<16 | $g<<8 | $b;
}
$sy = imagesy($im);
$sx = imagesx($im);
for($y=0;$y<$sy;$y++)
{
for($x=0;$x<$sx;$x++)
{
$rgba = imagecolorat($im, $x, $y);
$a = ($rgba & 0x7F000000) >> 24;
$r = ($rgba & 0xFF0000) >> 16;
$g = ($rgba & 0x00FF00) >> 8;
$b = ($rgba & 0x0000FF);
$lum = floor(($r*299+$g*587+$b*144)/1000);
imagesetpixel($im, $x, $y, $a<<24 | $pal[$lum]);
}
}
----
Server IP: 217.13.201.10
Probable Submitter: 80.141.4.52
----
Manual Page -- http://www.php.net/manual/en/function.substr.php
Edit -- https://master.php.net/note/edit/73213
Del: integrated -- https://master.php.net/note/delete/73213/integrated
Del: useless -- https://master.php.net/note/delete/73213/useless
Del: bad code -- https://master.php.net/note/delete/73213/bad+code
Del: spam -- https://master.php.net/note/delete/73213/spam
Del: non-english -- https://master.php.net/note/delete/73213/non-english
Del: in docs -- https://master.php.net/note/delete/73213/in+docs
Del: other reasons-- https://master.php.net/note/delete/73213
Reject -- https://master.php.net/note/reject/73213
Search -- https://master.php.net/manage/user-notes.php