Page 1 of 1

Animated Gif stored on a MySQL database

Posted: Sun Mar 23, 2008 7:23 pm
by lucian0c
Hi All:
I've got a table on a MySQL database with a LongBlob field. This field store an image, the image it is stored within a program written in C#. After that, i must render this image (gif image) in a web page, of course with PHP, this image is an "animation" (GIF89a). My code to render is:

$res = mysqli_query($link, "SELECT image FROM images");

if($row = mysqli_fetch_array($res))
{
if($row['image'] != null)
{
ob_clean();
header("Content-type: image/gif");
$im = imagecreatefromstring($row["image"]);
imagegif($im);
ob_flush();
flush();
imagedestroy($im);
}
}

This code works, but it only display the first FRAME of my Animated Gif. How do i do to display the animated gif with all the frames and the animation? I think that is something with GIF89a and GIF87, but i googled a lot and i cannot find anything-

Thanks a lot in advance.

Re: Animated Gif stored on a MySQL database

Posted: Mon Mar 24, 2008 3:19 pm
by www.WeAnswer.IT
This is not a direct answer to your question, but I hope you'll find it helpful.

I have been working with PHP and MySQL for years, and I have found that it is never a good idea to store images (even small ones) in a MySQL database, as opposed to storing them on the filesystem. Here's why:

1. Slower loading times (sometimes a lot slower).
2. Much more processing for your server.
3. Much more memory use for your server.
4. Takes up more harddisk dspace.
5. Much harder to write code (as you are finding out).

A much better solution is to store all of your files on your server in some folder, and then store the name of the file in your MySQL database. That's what most professional-quality PHP apps do, and it will save you a ton of time and effort.

Trying to store binary data in a MySQL database and then writing code to interpret it is a kind of "re-inventing the wheel" so to speak.