Gifencoderclass.php 的 gif 动画,来源不是 GIF
Animated gif with Gifencoderclass.php, source not GIF
我刚刚找到了用于制作动画 gif 的 php 库。
我想我已经正确编辑了示例代码,但我收到错误 GIFEncoder V2.05: 0 Source is not a GIF image!
。
有人用过这个 php class 可以帮助我吗?
下面是我使用的代码,我已经注释掉了"example"代码。
<?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 ( );
?>
您应该改用 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,所以才推荐的
我刚刚找到了用于制作动画 gif 的 php 库。
我想我已经正确编辑了示例代码,但我收到错误 GIFEncoder V2.05: 0 Source is not a GIF image!
。
有人用过这个 php class 可以帮助我吗?
下面是我使用的代码,我已经注释掉了"example"代码。
<?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 ( );
?>
您应该改用 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,所以才推荐的