converting a GIF to a PNG with PHP


You need to convert a GIF into a PNG.



Another short bit of PHP, which takes a GIF filename as a parameter and a compression tag,
so you can convert to PNG and change size too.

If you don’t want to compress the image, just use a value of 100.





$filename = $argv[1];
$compression = $argv[2];

Header("Content-type: image/png");

$im = imagecreatefromgif("$filename");


$newWidth=$currWidth * ($compression / 100);
$newHeight=$currHeight * ($compression / 100);

$im1 = imagecreatetruecolor($newWidth,$newHeight);
$bgc = imagecolorallocate ($im1,255,255,255);
imagefilledrectangle ($im1, 0, 0, $newWidth, $newHeight, $bgc);
imagecopyresampled ($im1, $im, 0, 0, 0, 0,
$newWidth, $newHeight, $currWidth, $currHeight);




[tags]Convert Images GIF PNG, PHP Coding School[/tags]


If you have found my website useful, please consider buying me a coffee below 😉

Leave a Reply

Your email address will not be published. Required fields are marked *