Markie
Posts: 251
|
| Posted: 02/04/2009, 11:38 AM |
|
On my server, I have GD v. 2 installed and phpinfo() tells me I have Gif support.
However, when I upload a gif file and look at the thumbnail on my webpage, I see this:
Warning: imagecreatefromgif() [function.imagecreatefromgif]: 'filename.gif' is not a valid GIF file in /var/www/mysite/HTML/thumbnail.inc.php on line 149
It's drivin' me nuts. I have tried all possible solutions I found with Google, but the problem still exists. It would be great if somebody in this forum knows why this error occurs.
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
damian
Posts: 838
|
| Posted: 02/04/2009, 2:51 PM |
|
i have a faint memory that you can actually use the jpg tools with gif images....
_________________
if you found this post useful take the time to help someone else.... :)
|
 |
 |
Markie
Posts: 251
|
| Posted: 02/04/2009, 11:52 PM |
|
For testing purposes I just uploaded a gif file with filezilla instead of with my file upload page and now imagecreatefromgif has no errors. It seems my file upload module corrupts gif files in some way. Anybody knows why and what to do ?
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
DonP
|
| Posted: 02/05/2009, 12:40 AM |
|
Possibly it uploaded as text rather than binary. Many FTP apps default
to text mode.
Don (DonP)
Markie wrote:
> On my server, I have GD v. 2 installed and phpinfo() tells me I have Gif
> support.
> However, when I upload a gif file and look at the thumbnail on my webpage, I
> see this:
>
> Warning: imagecreatefromgif() [function.imagecreatefromgif]: 'filename.gif' is
> not a valid GIF file in /var/www/mysite/HTML/thumbnail.inc.php on line 149
>
> It's drivin' me nuts. I have tried all possible solutions I found with Google,
> but the problem still exists. It would be great if somebody in this forum knows
> why this error occurs.
>
> _________________
> The Netherlands, GMT+1
> Tools: CCS 4.1.00.027, Win XP, Navicat, PSPad
> Local server: XAMPP with Apache, php and MySQL
> Webserver: Ubuntu with Apache, php and MySQL
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.yessoftware.com/
>
|
|
|
 |
Markie
Posts: 251
|
| Posted: 02/07/2009, 11:08 AM |
|
I did some thorough tests with the uploaded Gif files.
Before the upload, the file header of the Gif file is GIF89a (which is correct for a Gif file). After upload, the file header is JFIF (which is the file header for a Jpg file). Because of a still unknown problem, the header of the Gif file is turned into a header of a Jpg file:
JFIF..........ÿþ.>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality
because of the fact PHP is rather picky where it comes to corrupt images and therefore I see the imagecreatefromgif error.
If anybody knows a solution to my problem, please let me know 
by the way, the php code I use is this:
...
case "jpeg":
case "jpg":
$image = @imagecreatefromjpeg($uploadfile);
break;
case "gif":
$image = @imagecreatefromgif($uploadfile);
break;
case "png":
$image = @imagecreatefrompng($uploadfile);
break;
...
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
damian
Posts: 838
|
| Posted: 02/07/2009, 7:20 PM |
|
please see my post.... use imagecreatefromjpg() for gif extensions also (png too i think)
_________________
if you found this post useful take the time to help someone else.... :)
|
 |
 |
Markie
Posts: 251
|
| Posted: 02/08/2009, 9:33 AM |
|
@ damian: no, sorry, using imagecreatefromjpeg() for gif and png extensions doesn't work with me.
However, I have found the problem:
The cause of the fact that the file headers of Gif and Png files are changed to Jpg headers is this line in my php script:
imagejpeg($new_img, $thumbdir.$thumbnail);
When I change this to:
imagegif($new_img, $thumbdir.$thumbnail);
everything works out fine and the files are not corrupt anymore.
Question:
is it possible to make a code which recognizes the file extension, for example:
"if extension is jpg or jpeg, do
imagejpg($new_img, $thumbdir.$thumbnail);
if extension is gif, do
imagegif($new_img, $thumbdir.$thumbnail);
if extension is png, do
imagepng($new_img, $thumbdir.$thumbnail);"
Can anybody point me towards the right solution ?
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
datadoit
|
| Posted: 02/08/2009, 11:59 AM |
|
$ext = substr($fileName, strrpos($fileName, '.') + 1);
switch($ext) {
case "jpg":
do this;
break;
case "gif":
do that;
break;
case "png":
do other;
break;
}
|
|
|
 |
damian
Posts: 838
|
| Posted: 02/08/2009, 1:33 PM |
|
yeah.... i have something like:
//Load in File based on type
switch ( $type ):
case 'jpg':
$source = imagecreatefromjpeg($filepath);
break;
case 'JPG':
$source = imagecreatefromjpeg($filepath);
break;
case 'png':
$source = imagecreatefrompng($filepath);
break;
case 'PNG':
$source = imagecreatefrompng($filepath);
break;
case 'gif':
$source = imagecreatefromgif($filepath);
break;
case 'GIF':
$source = imagecreatefromgif($filepath);
break;
default:
echo "Invalid File Type";
endswitch;
_________________
if you found this post useful take the time to help someone else.... :)
|
 |
 |
datadoit
|
| Posted: 02/08/2009, 1:55 PM |
|
switch (strtoupper($type))
so you don't have to check for both upper and lower case values. Or
strtolower().
|
|
|
 |
damian
Posts: 838
|
| Posted: 02/08/2009, 6:52 PM |
|
good tip... so obvious! the things you learn as you go along :)
_________________
if you found this post useful take the time to help someone else.... :)
|
 |
 |
Markie
Posts: 251
|
| Posted: 02/09/2009, 10:36 AM |
|
Thanks guys, you made my day !
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
|