Page 1 of 2

Problem with imagecreatefromgif()

Posted: Tue Mar 21, 2006 7:38 am
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.

Posted: Tue Mar 21, 2006 10:16 am
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?

Posted: Tue Mar 21, 2006 10:21 am
by feyd
Are you 100% sure you saved it as a gif and not just named the file .gif?

Posted: Tue Mar 21, 2006 10:26 am
by spacebass5000
100% certain

Posted: Tue Mar 21, 2006 10:34 am
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?

Posted: Tue Mar 21, 2006 11:11 am
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

Posted: Tue Mar 21, 2006 12:12 pm
by feyd
it's a different file.

209 × 158 vs 220 × 136

Posted: Tue Mar 21, 2006 1:28 pm
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

Posted: Tue Mar 21, 2006 1:34 pm
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.

Posted: Tue Mar 21, 2006 2:04 pm
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?

Posted: Tue Mar 21, 2006 2:12 pm
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..

Posted: Tue Mar 21, 2006 2:33 pm
by spacebass5000
ah... ok

i shall manually ftp a copy of this to my site and see what comes of it

Posted: Tue Mar 21, 2006 3:03 pm
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

Posted: Tue Mar 21, 2006 3:09 pm
by spacebass5000
ok, the filename is derived from the $_FILES variable and the file gets put in place by "rename"

any thoughts on this?

Posted: Tue Mar 21, 2006 3:12 pm
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)..