PNG画像を8ビットPNGに変換するには、この関数を使用して、作成しました
function convertPNGto8bitPNG()
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);
}
パラメーター
$sourcePath-ソースPNGファイルへのパス$destPath-宛先PNGファイルへのパス使用法
convertPNGto8bitPNG('pfc.png', 'pfc8bit.png');