249, 'green'=>232, 'blue'=>89)); * imagepng($im, 'output.png'); * imagedestroy($im); * * @param resource Image created with for example imagecreatefrompng. * @param array Associative array with 'red', 'green' and 'blue' values * @return resource The input resource image colorized. * */ function colorize($im, $color) { imagetruecolortopalette($im, FALSE, 256); $ncolors = imagecolorstotal($im); for ($c = 0; $c<$ncolors; $c++) { $col = imagecolorsforindex($im, $c); // replaces original greyscale palette with a colorized one. imagecolorset($im, $c, $color['red']*$col['red']/256, $color['green']*$col['green']/256, $color['blue']*$col['blue']/256); } return $im; } ?>