Alpha have to be defined into 0 and 127. Then you have to use imagealphablending()
and imagesavealpha()
to save and use alpha.
$src = imagecreatefrompng('image.png');
imagealphablending($src, false);
imagesavealpha($src, true);
$w = imagesx($src);
$h = imagesy($src);
$alpha = round(204/255*127); // convert to [0-127]
for ($x = 0; $x < $w; $x++) {
for ($y = 0; $y < $h; $y++) {
// get current color (R, G, B)
$rgb = imagecolorat($src, $x, $y);
$r = ($rgb >> 16) & 0xff;
$g = ($rgb >> 8) & 0xff;
$b = $rgb & 0xf;
// create new color
$col = imagecolorallocatealpha($src, $r, $g, $b, $alpha);
// set pixel with new color
imagesetpixel($src, $x, $y, $col);
}
}
imagepng($src);
imagedestroy($src);