PHP Classes

Excellent class

Recommend this page to a friend!

      GIF images into animated GIF with native PHP class  >  All threads  >  Excellent class  >  (Un) Subscribe thread alerts  
Subject:Excellent class
Summary:Gif animation from JPEG Binary images from a MySQL database
Messages:3
Author:Damien Goor
Date:2009-02-01 17:04:06
Update:2009-02-19 11:53:22
 

  1. Excellent class   Reply   Report abuse  
Picture of Damien Goor Damien Goor - 2009-02-01 17:04:06
Using this class I was able to turn a simple Flash slideshow into a gif animation. The purpose was to be able to insert html into eBay promoting my customer web site. eBay for security reasons does not accept any Flash or Javascript. This class brought us the solution. I was not able to avoid to save the gif images before generating the animation ... but OK no worries. Images are "un-cropped" to make them all at the same size (in my case all image have max size of 167*167 but may be smaller.

Here is my code:

<?php
include("connect.php");
include "GIFEncoder.class.php";
//get image binary string
$qry = "SELECT thumb
FROM anim, articles, pictures
WHERE anim.artId = articles.artId AND anim.artId = pictures.artId AND pictures.seq = 0";
$result = mysql_query($qry);
$frames = array();
$delays = array();
$i = 0;
while($row = mysql_fetch_assoc($result)){
//Max height 167 and 2px more at the bottom to make it nicer
$destPic = imagecreatetruecolor(167, 169);
$image = imagecreatefromstring($row["thumb"]);
$w = imagesx($image);
$h = imagesy($image);
imagecopy($destPic, $image, (167 - $w)/2, (167 - $h)/2, 0, 0, $w, $h);
imagetruecolortopalette($destPic, true, 255);
//write the gif file to disk
imagegif($destPic, "tgif" . $i . ".gif");
array_push($frames, "tgif" . $i . ".gif");
array_push($delays, 200);
$i++;
}
$gif = new GIFEncoder (
$frames,
$delays,
0,
2,
0, 0, 0,
"url"
);
//save animation
FWrite(FOpen("anim.gif","wb"), $gif->GetAnimation());
//remove temp gif's
for($x=0;$x<$i;$x++){
unlink("tgif".$x.".gif");
}
?>

  2. Re: Excellent class   Reply   Report abuse  
Picture of László Zsidi László Zsidi - 2009-02-01 17:37:02 - In reply to message 1 from Damien Goor
Thank you for your excellent feedback.
Why store all generated frames on your webserver?
You can generate frames and build these frames as one animation on the fly.

<?php
include("connect.php");
include "GIFEncoder.class.php";
//get image binary string
$qry = "SELECT thumb
FROM anim, articles, pictures
WHERE anim.artId = articles.artId AND anim.artId = pictures.artId AND pictures.seq = 0";
$result = mysql_query($qry);
$frames = array();
$delays = array();
$i = 0;
while($row = mysql_fetch_assoc($result)){
//Max height 167 and 2px more at the bottom to make it nicer
$destPic = imagecreatetruecolor(167, 169);
$image = imagecreatefromstring($row["thumb"]);
$w = imagesx($image);
$h = imagesy($image);
imagecopy($destPic, $image, (167 - $w)/2, (167 - $h)/2, 0, 0, $w, $h);
imagetruecolortopalette($destPic, true, 255);
//write the gif file to disk
//imagegif($destPic, "tgif" . $i . ".gif");
//array_push($frames, "tgif" . $i . ".gif");
//array_push($delays, 200);
//$i++;
ob_start();
imagegif($destPic);
$frames [] = ob_get_contents();
$framed [] = 200;
ob_end_clean();
imageDestroy($destPic);
}
$gif = new GIFEncoder (
$frames,
$delays,
0,
2,
0, 0, 0,
"bin"
);
//save animation
FWrite(FOpen("anim.gif","wb"), $gif->GetAnimation());
//remove temp gif's
//for($x=0;$x<$i;$x++){
//unlink("tgif".$x.".gif");
}
?>

  3. Re: Excellent class   Reply   Report abuse  
Picture of Damien Goor Damien Goor - 2009-02-19 11:53:22 - In reply to message 2 from László Zsidi
Would be better to avoid it but it did not work for me.