保持gif动画

时间:2012-04-27 13:46:08

标签: php gif

我正在使用以下脚本生成动画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的检查似乎有效,但我无法维持它。非常感谢任何帮助。

0 个答案:

没有答案
相关问题