jaymc Posted September 27, 2006 Share Posted September 27, 2006 I have an upload script that allows people to upload images, adds a bit of text on the image then displays itThis works great, but, here is the problemIt only works if the file was saved as a JPG!If the image the upload is a gif, then the image does not display. My script needs to support atleast jpeg, gif bmp & pngObviously imagejpeg() does not support anything other than true jpg filesAny way around it / alternitives? Quote Link to comment https://forums.phpfreaks.com/topic/22311-image-jpggif/ Share on other sites More sharing options...
brendandonhue Posted September 27, 2006 Share Posted September 27, 2006 Are you using imagecreatefromjpeg()? You need to use imagecreatefromgif() if you want to load a GIF image. Quote Link to comment https://forums.phpfreaks.com/topic/22311-image-jpggif/#findComment-99942 Share on other sites More sharing options...
jaymc Posted September 28, 2006 Author Share Posted September 28, 2006 well the problem is, the gif files are saved as .jpgSo they are true gif files but named file.jpg, so I cant determine if they are gif or not as I cant go by the file extension Quote Link to comment https://forums.phpfreaks.com/topic/22311-image-jpggif/#findComment-99961 Share on other sites More sharing options...
Barand Posted September 28, 2006 Share Posted September 28, 2006 Perhaps if you posted some code we wouldn't have to guess what's wrong. Quote Link to comment https://forums.phpfreaks.com/topic/22311-image-jpggif/#findComment-99969 Share on other sites More sharing options...
jaymc Posted September 28, 2006 Author Share Posted September 28, 2006 [code]<?// File and new size$userpic = $_GET['user'];$filename = "pics/".$userpic.".jpg";// Content type header('Content-type: image/jpeg'); // Date in the past, so that the image is not cached by the browser Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Get new sizeslist($width, $height) = getimagesize($filename);$newwidth = 76;$newheight = 62;// Load$thumb = imagecreatetruecolor($newwidth, $newheight);$source = imagecreatefromjpeg($filename);// Resizeimagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);// Outputimagejpeg($thumb, null, 100);?> [/code] Quote Link to comment https://forums.phpfreaks.com/topic/22311-image-jpggif/#findComment-99972 Share on other sites More sharing options...
Barand Posted September 28, 2006 Share Posted September 28, 2006 getimagesize() will also tell you the type of the filelist($width, $height, $type) = getimagesize($filename);Use the type info to adjust your code accordingly Quote Link to comment https://forums.phpfreaks.com/topic/22311-image-jpggif/#findComment-99986 Share on other sites More sharing options...
jaymc Posted September 28, 2006 Author Share Posted September 28, 2006 Great, Ive got it working using the following approach[code]if ($type[2] == 1) {$source = imagecreatefromgif($filename);}else if ($type[2] == 2) {$source = imagecreatefromjpeg($filename);}else if ($type[2] == 3) {$source = imagecreatefrompng($filename);}else if ($type[2] == 4) {$source = imagecreatefromjpeg($filename);}else if ($type[2] == 6) {$source = imagecreatefrombmp($filename);}[/code]However, their is no [b]imagecreatefrombmp[/b]How do I handle bmp images? Quote Link to comment https://forums.phpfreaks.com/topic/22311-image-jpggif/#findComment-100168 Share on other sites More sharing options...
Barand Posted September 28, 2006 Share Posted September 28, 2006 Not supported by GD. But if you want to process themhttp://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html Quote Link to comment https://forums.phpfreaks.com/topic/22311-image-jpggif/#findComment-100175 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.