I just created the following code and it works wonders.
Beware: If you set $backgroundTransparent to false, the image may lose quality when the background is painted under it.
<?php
$width = 256;
$height = 256;
$backgroundColor = array(0, 255, 0);
$backgroundTransparent = true;
$icon = imagecreatefrompng('Access-New.png');
imagealphablending($icon, false);
imagesavealpha($icon, true);
imagefilter($icon, IMG_FILTER_BRIGHTNESS, -255);
imagefilter($icon, IMG_FILTER_COLORIZE, 255, 0, 0);
if($backgroundTransparent == false) {
$background = imagecreatetruecolor($width, $height);
imagefill($background, 0, 0, imagecolorallocate($background, $backgroundColor[0], $backgroundColor[1], $backgroundColor[2]));
imagealphablending($icon, true);
imagecopy($background, $icon, 0, 0, 0, 0, $width, $height);
imagepng($background, NULL, 0, PNG_NO_FILTER);
}
else {
imagepng($icon, NULL, 0, PNG_NO_FILTER);
}
header("Content-type: image/png");
imagedestroy($background);
?>