2

我正在使用以下脚本生成动画 GIF: http: //www.jeroenvanwissen.nl/weblog/php/howto-generate-animated-gif-with-php

if (!getimagesize($_FILES['myfile']['tmp_name']))
{
    array_push($errors, 'Invalid image file');
}
else
{
    $uploaded_type = exif_imagetype($_FILES["myfile"]["tmp_name"]); 

    switch($uploaded_type) 
    {
        case '1':
            $uploaded_type = 'gif';

            if(is_ani($_FILES['myfile']['tmp_name']))
                $is_animated = true;

            $image = imagecreatefromgif($_FILES['myfile']['tmp_name']);


        break;
        case '2':
            $uploaded_type = 'jpg';
            $image = imagecreatefromjpeg($_FILES['myfile']['tmp_name']);
        break;
        case '3':
            $uploaded_type = 'png';
            $image = imagecreatefrompng($_FILES['myfile']['tmp_name']);
        break;
    }

    list($width, $height, $type, $attr) = getimagesize($_FILES['myfile']['tmp_name']);
    $originalWidth = $width;
    $originalHeight = $height;
}

$new_image = imagecreatetruecolor($newWidth, $newHeight);

imagecopyresampled($new_image, $image, 0, 0, 0, 0, $newWidth, $newHeight, $originalWidth, $originalHeight); 

ob_start();
imagegif($new_image);
$frames[]=ob_get_contents();
$framed[]=40; 
ob_end_clean();

ob_start();
imagegif($new_image);
$frames[]=ob_get_contents();
$framed[]=40; 
ob_end_clean();

$gif = new GIFEncoder($frames,$framed,0,2,0,0,0,'bin');

$fp = fopen($baseUrl . $filename, 'w');
fwrite($fp, $gif->GetAnimation());
fclose($fp);

如果已经存在,有什么方法可以保留 gif 动画?我对动画 gif 的检查似乎有效,但我无法维护它。任何帮助深表感谢。

4

0 回答 0