PHP 8.5.0 Alpha 1 available for testing

Voting

: five minus two?
(Example: nine)

The Note You're Voting On

dade dot c at email dot it
20 years ago
this is helpful if you would like to implement a color theme system in your website... try it out
Davide Candiloro Italy

function colorize ($pngpath, $r, $g, $b)
/*
REQUIRES: $pngpath to be a valid path of a greyscale PNG-8 image with 64 colors palette
$r, $g, $b to be integers in the range 0..255
EFFECTS: returns the png image colorized with the color represented by $r, $g, $b.
*/
{
header("Content-type: image/png");
$im = imagecreatefrompng("images/table.png");

imagetruecolortopalette($im, FALSE, 256);

for ($c = 0; $c < 64; $c++){ /*64 is the number of colors in the PNG-8 palette*/
$col = imagecolorsforindex($im, $c);
imagecolorset ( $im, $c, $r*$col['red']/256, $g*$col['green']/256, $b*$col['blue']/256); /*replaces original greyscale palette with a colorized one*/
}

imagepng($im);
imagedestroy($im);
}

<< Back to user notes page

To Top