【问题标题】:Animated GIF with PHP使用 PHP 制作 GIF 动画
【发布时间】:2012-08-23 01:14:02
【问题描述】:

我想创建一个带有透明背景的动画像素的 GIF 图像,它从 Javascript 中获取颜色。 我尝试使用这个: http://www.phpclasses.org/package/3163-PHP-Generate-GIF-animations-from-a-set-of-GIF-images.html 还有这个:http://www.jeroenvanwissen.nl/weblog/php/howto-generate-animated-gif-with-php 但是,我有一个问题。 我创建了这段代码:

<?php
header ('Content-type:image/gif');
include('GIFEncoder.class.php');

// Open the first source image and add the text.
$image = imagecreatefrompng('None.png');
imagesavealpha($image, true);
$color = $_GET["sc"];
$r_bg = hexdec(substr($color,0,2));
$g_bg = hexdec(substr($color,2,2));
$b_bg = hexdec(substr($color,4,2));
$c1 = imagecolorallocate($image, $r_bg, $g_bg, $b_bg);
imagesetpixel($image,36,24,$c1);
imagesetpixel($image,36,25,$c1);
imagesetpixel($image,36,26,$c1);
imagesetpixel($image,37,26,$c1);
imagesetpixel($image,38,26,$c1);
imagesetpixel($image,38,25,$c1);
imagesetpixel($image,38,24,$c1);
imagesetpixel($image,37,24,$c1);

// Generate GIF from the $image
// We want to put the binary GIF data into an array to be used later,
//  so we use the output buffer.
ob_start();
imagegif($image);
$frames[]=ob_get_contents();
$framed[]=40;

// Delay in the animation.
ob_end_clean();

// And again..
// Open the first source image and add the text.
$image = imagecreatefrompng('None.png');
imagesavealpha($image, true);
$color = $_GET["sc"];
$r_bg = hexdec(substr($color,0,2));
$g_bg = hexdec(substr($color,2,2));
$b_bg = hexdec(substr($color,4,2));
$c1 = imagecolorallocate($image, $r_bg, $g_bg, $b_bg);
imagesetpixel($image,34,23,$c1);
imagesetpixel($image,34,24,$c1);
imagesetpixel($image,34,25,$c1);
imagesetpixel($image,34,26,$c1);
imagesetpixel($image,34,27,$c1);
imagesetpixel($image,35,28,$c1);
imagesetpixel($image,36,28,$c1);
imagesetpixel($image,37,28,$c1);
imagesetpixel($image,38,28,$c1);
imagesetpixel($image,39,28,$c1);
imagesetpixel($image,40,27,$c1);
imagesetpixel($image,40,26,$c1);
imagesetpixel($image,40,25,$c1);
imagesetpixel($image,40,24,$c1);
imagesetpixel($image,40,23,$c1);
imagesetpixel($image,39,22,$c1);
imagesetpixel($image,38,22,$c1);
imagesetpixel($image,37,22,$c1);
imagesetpixel($image,36,22,$c1);
imagesetpixel($image,35,22,$c1);

// Generate GIF from the $image
// We want to put the binary GIF data into an array to be used later,
//  so we use the output buffer.
ob_start();
imagegif($image);
$frames[]=ob_get_contents();
$framed[]=40;

// Delay in the animation.
ob_end_clean();

// Generate the animated gif and output to screen.
$gif = new GIFEncoder($frames,$framed,0,2,0,0,0,'bin');
echo $gif->GetAnimation();
?>

我得到一个十六进制颜色代码,然后将其更改为 RGB。 但是,我得到了这些错误:

<br />
<b>Notice</b>:  Use of undefined constant ERR00 - assumed 'ERR00' in <b>D:\Testing\xampp\htdocs\Test\Test.php</</b> on line <b>75</b><br />
<br />
<b>Notice</b>:  Use of undefined constant ERR01 - assumed 'ERR01' in <b>D:\Testing\xampp\htdocs\Test\Test.php</</b> on line <b>75</b><br />
<br />
<b>Notice</b>:  Use of undefined constant ERR02 - assumed 'ERR02' in <b>D:\Testing\xampp\htdocs\Test\Test.php</b> on line <b>75</b><br />
<br />
<b>Notice</b>:  Use of undefined constant ERR03 - assumed 'ERR03' in <b>D:\Testing\xampp\htdocs\Test\Test.php</b> on line <b>75</b><br />
GIF89a2

我不知道这是问题所在。 :/

【问题讨论】:

    标签: php jquery-animate png gif


    【解决方案1】:

    检查你的 GIFEncoder 类。有一些未定义的变量。试试看empty($for_all_vars);

    或查看this

    【讨论】:

      【解决方案2】:

      供将来参考:我今天遇到了这个错误。发生这种情况是因为那个 10 岁以上的 GIFEncoder 库中有错误的语法。在定义 $ERR 数组的地方,缺少数组键周围的引号。

      正确的代码 sn-p 必须是:

      var $ERR = Array (
          'ERR00'=>"Does not supported function for only one image!",
          'ERR01'=>"Source is not a GIF image!",
          'ERR02'=>"Unintelligible flag ",
          'ERR03'=>"Does not make animation from animated GIF source",
      );
      

      (注意 ERR00 到 ERR03 周围的引号,这些在网络上浮动的原始文件中丢失了。)

      希望这对某人有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-07-19
        • 1970-01-01
        • 1970-01-01
        • 2011-01-10
        • 1970-01-01
        相关资源
        最近更新 更多