note 73213 deleted from function.substr by cmb

From: Date: Sun, 27 Oct 2019 09:03:43 +0000
Subject: note 73213 deleted from function.substr by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212816@lists.php.net to get a copy of this message
Note Submitter: persisteus at web dot de ---- Here is also a nice (but a bit slow) alternative for colorizing an true color image: <?php // $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]); } } ?>

« previous php.notes (#212816) next »