Hello guys
Basically i am trying to create a function that will automatically convert 32/24 bit png file to 8bit PNG with alpha support and good quality
However all solutions i tried with php gd give me low quality png files
My function is similar to code below
Sites like TinyPNG use it and i would like to integrate this in my php script.
I am still learning php and i suppose the way to execute command line instructiond for pngquant would be to use the
I am coding my script on a WAMP atm and i don't have a linux system at hand.
Can anyone be kind enough to show me a simple code snippet to make pngquant work in php.
Also i would like to know what stuff need to install on a Centos server to support pngquant
Regards
Basically i am trying to create a function that will automatically convert 32/24 bit png file to 8bit PNG with alpha support and good quality
However all solutions i tried with php gd give me low quality png files
My function is similar to code below
I found something while googling and its called pngquant.orgfunction 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);
}
Sites like TinyPNG use it and i would like to integrate this in my php script.
I am still learning php and i suppose the way to execute command line instructiond for pngquant would be to use the
commandexec()
I am coding my script on a WAMP atm and i don't have a linux system at hand.
Can anyone be kind enough to show me a simple code snippet to make pngquant work in php.
Also i would like to know what stuff need to install on a Centos server to support pngquant
Regards