1

我用这个函数来更新一个动态的 GIF 图片,但是 GD 把它渲染成静态的?

function draw_image ()

  {

    $img=imagecreatefromgif('images/moni.gif');

    $text='test';
    $lastpayout='test'; 
    $colors['name'] = imagecolorallocate($img, 999, 000, 156);
    ImageTTFText($img, 9, 0, 20, 235, $colors['name'], "images/impact.ttf", $text);
    ImageTTFText($img, 9, 0, 20, 250, $colors['name'],"images/tahoma.ttf",$lastpayout);
    ImageTTFText($img, 10, 0, 15, 270, $colors['name'], "images/tahoma.ttf", $text);
    header("Content-type: image/gif");
    imagegif($img);
  }

echo  draw_image ();

此函数将动画 GIF 转换为静态 GIF。谁能帮我?

4

2 回答 2

2

如果你可以使用imagick

$gif = new Imagick('full/path/to/your/image.gif');

$draw = new ImagickDraw();    
$draw->setFont('full/path/to/your/font.ttf');
$draw->setFontSize(30);
$draw->setFillColor('white');

// put text on each frame
foreach($gif as $frame){
  $gif->annotateImage($draw, $x = 10, $y = 45, $angle = 0, 'Your text');         
}    

header('Content-Type: image/gif');
print $gif->getImagesBlob();
于 2013-05-17T12:11:48.590 回答
1

GD 不支持动画 GIF。你可以试试imagick。

于 2013-05-17T11:54:51.683 回答