As creamdog noted before, the alpha channel IS available from this function! (The manual should probably be updated to include this!)
$rgba = imagecolorat($im,$x,$y);
$alpha = ($rgba & 0x7F000000) >> 24;
$alpha will then contain the TRANSPARENCY (NOT OPACITY) level. So 127, the max, would be completely transparent, and 0 would be completely opaque.
Using this information, it is possible to write a dithering png-to-gif function like the completely working simple one below:
<?php
$im = imagecreatefrompng($pngRel);
$transparentColor = imagecolorallocate($im, 0xfe, 0x3, 0xf4 );
$height = imagesy($im);
$width = imagesx($im);
for($x = 0; $x < $width; $x++){
for($y = 0; $y < $height; $y++) {
$alpha = (imagecolorat($im,$x,$y) & 0x7F000000) >> 24;
if ($alpha > 3 && (
$alpha >=127-3 ||
(rand(0,127))>=(127-$alpha)
)){
imagesetpixel($im,$x,$y,$transparentColor);
}
}
}
imagecolortransparent($im, $transparentColor);
imagegif($im, $gifRel);header("Content-type: image/gif");
readfile($gifRel); ?>