Skip to content

Instantly share code, notes, and snippets.

@gesior
Created July 29, 2015 08:02
Show Gist options
  • Save gesior/6f5f7d15cb50f59a88fd to your computer and use it in GitHub Desktop.
Save gesior/6f5f7d15cb50f59a88fd to your computer and use it in GitHub Desktop.
<?php
$from = 'items'; // images PNG folder
$to = 'gif'; // empty folder
function png2gif($pngs, $background = array(255, 255, 255), $dest = 'gif')
{
// by WebReflection
foreach($pngs as $png){
$size = getimagesize($png);
$img = imagecreatefrompng($png);
$image = imagecreatetruecolor($width = $size[0], $height = $size[1]);
imagefill($image, 0, 0, $bgcolor = imagecolorallocate($image, $background[0], $background[1], $background[2]));
imagecopyresampled($image, $img, 0, 0, 0, 0, $width, $height, $width, $height);
imagecolortransparent($image, $bgcolor);
imagegif($image, str_ireplace('.png', '.gif', $dest.DIRECTORY_SEPARATOR.basename($png)), 100);
imagedestroy($image);
}
}
png2gif(glob($from . "/*.png"), $background = array(255, 255, 255), $to);
@fwcanlam
Copy link

If you know, pls help me: Sybio/ImageWorkshop#95

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment