imagecreatefromgif

Description

resourceimagecreatefromgif
( string$filename
)

imagecreatefromgif() returns an image identifier
representing the image obtained from the given filename.

Tip

A URL can be used as a
filename with this function if the fopen wrappers have been enabled.
See fopen() for more details on how to specify the
filename. See the Supported Protocols and Wrappers for links to information
about what abilities the various wrappers have, notes on their usage,
and information on any predefined variables they may
provide.

Hopefully this might save someone a headache when using functions to check for animated GIFs.

I have come across some some GIFs use the a different frame separator sequence, \x00\x21, instead of the official standard \x00\x2C. This seems to be happening with animated GIFs saved in Photoshop CS5, although I'm not quite sure if that's where the issue is originating from.

Anyway, I've been using the pattern:"#\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)#s"which seems to cover all GIFs, hopefully without misinterpreting.

I wanted to find out if a GIF is Black & White or Color, but I didn't want to wait around for imagecreatefromgif() to parse a 200k file (about 1 second) to get the color map, so I wrote this function to get a list of all the colors in the GIF. Hope it is useful for you.

I just installed gif2png on my server, and it took a little research on my part to figure out that this...

passthru("$path/gif2png -O $image_path/image.gif")

will not work if safe mode is on. If you're on a shared server, it probably is. You don't need to turn safe mode off, however, just set the safe_mode_exec_dir variable in your php.ini file to the directory where you installed gif2png. Then you'll be able to execute the program from your PHP script.

In Win32, passthru("gif2png $filename");works fine if gif2png.exe is in the path.It will overwrite the file with .png extension, so be careful,or use temp files as in the post referenced above (without the -O; type "gif2png" at the command line for the options).

I had a problem with exceeding the default 30 second execution time limit in PHP, so I added this line set_time_limit(0); // some odd gifs take a long time (example, a 25K gif, 700x700, mostly blank)

After hours of search, I've finally found a program which can convert JPG to GIF.IJG - The Independent JPEG Group's JPEG softwareVersion 6 which support GIF (read and write with LZW)and the version 6b which support GIF (write only without LZW)

FreeBSD users are lucky to have the option of compiling GIF support in GD2.x through the ports system.All you need to do is to export the "WITH_LZW=yes" global variable when compiling the graphics/gd2 port, e.g.:

Since gif support is removed from the more recent GD libraries, you can still use it via an external program.
I've read somewhere about using ImageMagick and I tried myself but it's a quite big package and needs the X11 libs which are not available in some servers.
The other option I found is to use a little prog "gif2png" http://www.tuxedo.org/~esr/gif2png/to convert gif files to png ones. It works under Unix and dos/win32/winnt and is very straightforward.
If you need to modify an user uploaded gif file to save it into your site just use this:

basically what that does is reads the file..through the "GetImageSize", which still returns if it's a GIF or not, (thank god), then if it's a gif, opens the file through normal filestream, sets the header to image type "gif" then prints it out. Same as doing "ImageCreateFromGif($img)" and "ImageGif($img)", except that it doesn't require GD Gif support. If you have any questions just ask me via email (chuckg@infinite9.com)

# if this is a url, use fopen to get the file data, then
# save it to a dummy file
if (preg_match("/(http|ftp):\/\//i", $file_or_url)) {
# open the file using fopen, which supports remote URLs
$input = fopen($file_or_url, "rb");

# read the contents of the file
# will accept files up to 10Mb, but will probably get
# and EOF before that, we have to do it this way because
# filesize isn't designed to work with URLs. sigh.
$image_data = fread($input, 10000000);