To convert any PNG image to 8-bit PNG, use this function, I just created
convertPNGto8bitPNG () function
function convertPNGto8bitPNG($sourcePath, $destPath) { $srcimage = imagecreatefrompng($sourcePath); list($width, $height) = getimagesize($sourcePath); $img = imagecreatetruecolor($width, $height); $bga = imagecolorallocatealpha($img, 0, 0, 0, 127); imagecolortransparent($img, $bga); imagefill($img, 0, 0, $bga); imagecopy($img, $srcimage, 0, 0, 0, 0, $width, $height); imagetruecolortopalette($img, false, 255); imagesavealpha($img, true); imagepng($img, $destPath); imagedestroy($img); }
Parameters
- $ sourcePath - path to the PNG source file
- $ destPath - Path to destination PNG file.
Using
convertPNGto8bitPNG('pfc.png', 'pfc8bit.png');
Example (original โ 8 bit)
(Source: pfc.png) ORIGINAL PNG IMAGE

(Purpose: pfc8bit.png) PNG CONVERTED IMAGE (8 bits)

Note. I have not tried this feature with transparent images. I think it works, but I'm not 100% sure.Hope this helps.
source share