Problem with imagecreatefromgif()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

spacebass5000
Forum Newbie
Posts: 11
Joined: Tue Mar 21, 2006 7:31 am

Problem with imagecreatefromgif()

Post by spacebass5000 »

My webserver uses:

PHP Version 4.4.2
Zend Optimizer v2.5.10

gd
GD Support enabled
GD Version bundled (2.0.28 compatible)
FreeType Support enabled
FreeType Linkage with freetype
GIF Read Support enabled
GIF Create Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
XBM Support enabled

I am simply tring to use imagecreatefromgif() to create a gif. I keep getting the following error:

Warning: imagecreatefromgif(): '/home/omnipcs/public_html/devel/example/components/com_mtree/img/listings/34_test.gif' is not a valid GIF file in /home/omnipcs/public_html/devel/example/components/com_example/includes/example.image.functions.php on line 36

The file is indeed where it should be, it exists, and is a gif that I JUST created in photoshop. I cannot seem to get around this error and I have found nothing on the web to help me.

Can anyone here shed any light onto why I am getting this error? This is how the function is being called:

$logo = imagecreatefromgif($image);

Image points to: /home/omnipcs/public_html/devel/example/components/com_mtree/img/listings/34_test.gif

Which like I said, exists and is in fact a gif.
spacebass5000
Forum Newbie
Posts: 11
Joined: Tue Mar 21, 2006 7:31 am

Post by spacebass5000 »

ok, looking at the gd home page and then following it to http://www.nyphp.org/content/presentations/GDintro/

i came across using getImageSize to print out the images pertinent info. I am getting this:

Code: Select all

Array ( [0] => 220 [1] => 136 [2] => 2 [3] => width="220" height="136" [bits] => 8 [channels] => 3 [mime] => image/jpeg )
for a gif. Note the mime setting. Why on earth would this happen? Could it be an improper server config?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Are you 100% sure you saved it as a gif and not just named the file .gif?
spacebass5000
Forum Newbie
Posts: 11
Joined: Tue Mar 21, 2006 7:31 am

Post by spacebass5000 »

100% certain
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

well.. considering getimagesize() says you have a 32bit image of type jpeg, it would appear you didn't. Care to put this file somewhere we can see it?
spacebass5000
Forum Newbie
Posts: 11
Joined: Tue Mar 21, 2006 7:31 am

Post by spacebass5000 »

the streets will flow with the blood of the non-believers!!! :D

http://www.omnipcsolutions.com/devel/di ... _test3.GIF

awesome paint skills
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it's a different file.

209 × 158 vs 220 × 136
spacebass5000
Forum Newbie
Posts: 11
Joined: Tue Mar 21, 2006 7:31 am

Post by spacebass5000 »

doesn't matter, same results...

Code: Select all

Array ( [0] => 209 [1] => 158 [2] => 2 [3] => width="209" height="158" [bits] => 8 [channels] => 3 [mime] => image/jpeg ) image/jpeg

image/jpeg
thanks for your help btw
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

[feyd@home]>php -r "$filename = 'http://www.omnipcsolutions.com/devel/dineus/components/com_mtree/img/listings/34_test3.GIF'; var_export(getimagesize($filename)); $file = file_get_contents($filename); echo substr($file, 0, 15);"
array (
  0 => 209,
  1 => 158,
  2 => 2,
  3 => 'width="209" height="158"',
  'bits' => 8,
  'channels' => 3,
  'mime' => 'image/jpeg',
) ╪ α ►JFIF ☺☺
Outputting the first 15 bytes of the file tells me that getimagesize() is correct. It is a JPEG file.
spacebass5000
Forum Newbie
Posts: 11
Joined: Tue Mar 21, 2006 7:31 am

Post by spacebass5000 »

ok, but... I made the file in paint. I saved it as a gif. It is a gif. I did the same thing with photoshop. Trust me when I say that I know how to create and edit graphics. That file, is a gif as far as paint and photoshop are concerned.

I also grabbed some gifs from around the web and I get the same results.

Can you shed any light onto what the problem might be?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it's in some way being converted to a jpeg file. How, I don't know, since I don't know how your server or scripts are set up..
spacebass5000
Forum Newbie
Posts: 11
Joined: Tue Mar 21, 2006 7:31 am

Post by spacebass5000 »

ah... ok

i shall manually ftp a copy of this to my site and see what comes of it
spacebass5000
Forum Newbie
Posts: 11
Joined: Tue Mar 21, 2006 7:31 am

Post by spacebass5000 »

I'll be damned...

Code: Select all

Array ( [0] => 209 [1] => 158 [2] => 1 [3] => width="209" height="158" [bits] => 8 [channels] => 3 [mime] => image/gif )
THANK YOU VERY VERY MUCH!

Now I have to suss out just wth it is that is doing this. 8O
spacebass5000
Forum Newbie
Posts: 11
Joined: Tue Mar 21, 2006 7:31 am

Post by spacebass5000 »

ok, the filename is derived from the $_FILES variable and the file gets put in place by "rename"

any thoughts on this?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You mean rename()? You should use move_uploaded_file() when dealing with uploaded files. basename() should be used against the given name to make sure you get just the filename (if you want to even trust that much)..
Post Reply