2016-04-28 111 views
1

我剛剛找到了製作動畫gif的php庫。
我認爲我編輯了正確的示例代碼,但出現錯誤GIFEncoder V2.05: 0 Source is not a GIF image!Gifencoderclass.php的動畫gif,源碼不是GIF

任何已經使用過這個php類,可以幫助我嗎?
下面是我使用的代碼,我已經註釋掉了「示例」代碼。

<?php 

include "GIFEncoder.class.php"; 
/* 
Build a frames array from sources... 

if ($dh = opendir ("frames/")) { 
while (false !== ($dat = readdir ($dh))) { 
    if ($dat != "." && $dat != "..") { 
     $frames [ ] = "frames/$dat"; 
     $framed [ ] = 5; 
    } 
} 
closedir ($dh); 
} 
*/ 
$frames = array("http://www.hoppvader.nu/weatherpics/Windsock1/windsock-10.gif","http://www.hoppvader.nu/weatherpics/Windsock1/windsock-20.gif","http://www.hoppvader.nu/weatherpics/Windsock1/windsock-30.gif"); 
$framed = array(40, 80, 40); 
/* 
    GIFEncoder constructor: 
    ======================= 

    image_stream = new GIFEncoder (
         URL or Binary data 'Sources' 
         int     'Delay times' 
         int     'Animation loops' 
         int     'Disposal' 
         int     'Transparent red, green, blue colors' 
         int     'Source type' 
        ); 
*/ 
$gif = new GIFEncoder (
         $frames, 
         $framed, 
         0, 
         2, 
         0, 0, 0, 
         "url" 
    ); 
/* 
    Possibles outputs: 
    ================== 

    Output as GIF for browsers : 
     - Header ('Content-type:image/gif'); 
    Output as GIF for browsers with filename: 
     - Header ('Content-disposition:Attachment;filename=myanimation.gif'); 
    Output as file to store into a specified file: 
     - FWrite (FOpen ("myanimation.gif", "wb"), $gif->GetAnimation ()); 
*/ 
Header ('Content-type:image/gif'); 
echo $gif->GetAnimation (); 
?> 

回答

0

您應該使用Gifcreator代替:

https://github.com/Sybio/GifCreator

<?php 
    include "GifCreator.php"; 

    // create an array with images 
    $frames = array(imagecreatefromjpeg("pic1.jpg"), 
        imagecreatefromjpeg("pic2.jpg"), 
        imagecreatefromjpeg("pic3.jpg")); 

    // the time each image should be visible in ms 
    $time = array(20,20,20); 

    // create the gif-image 
    $gc = new \GifCreator\GifCreator(); 
    $gc->create($frames, $durations, 0); 

    $gifBinary = $gc->getGif(); 

    header('Content-type: image/gif'); 
    header('Content-Disposition: filename="GIF-image"'); 

    //echo the GIF-image 
    echo $gifBinary; 

?> 

我沒有用過GIFencoder,但我已經使用GIFcreator,這就是爲什麼我建議它。