scooter41 Posted May 21, 2008 Share Posted May 21, 2008 Hi there, A client of mine takes his photos straight off his camera and uses our image uploader to add product shots to his website. The script we use normally works without any problems, however his images seem to be causing the script to fall over, saying it cant open the jpeg file. Im using the function as follows: function open_image ($file) { # JPEG: $im = @imagecreatefromjpeg($file); if ($im !== false) { return $im; } # GIF: $im = @imagecreatefromgif($file); if ($im !== false) { return $im; } # PNG: $im = @imagecreatefrompng($file); if ($im !== false) { return $im; } # WBMP: $im = @imagecreatefromwbmp($file); if ($im !== false) { return $im; } # Try and load from string: $im = @imagecreatefromstring(file_get_contents($file)); if ($im !== false) { return $im; } return false; } Where none of the options works, and it fails saying unable to open image. Could it be something to do with the exif data that is present in jpegs straight from the camera? I have tried options my end, such as cmyk instead of RGB, and 300dpi instead of 72dpi, but they all work fine and I am unable to recreate the error, so I am almost working blind. Appreciate any suggestions anyone has!! Thanks in advance Link to comment https://forums.phpfreaks.com/topic/106621-unable-to-readopen-uploaded-jpeg-files-from-digital-camera/ Share on other sites More sharing options...
BlueSkyIS Posted May 21, 2008 Share Posted May 21, 2008 i suggest that you use getimagesize() to check the type of the image first, then process it accordingly; vs. imagecreatefromxxx multiple times to see if it works. Link to comment https://forums.phpfreaks.com/topic/106621-unable-to-readopen-uploaded-jpeg-files-from-digital-camera/#findComment-546483 Share on other sites More sharing options...
The Little Guy Posted May 21, 2008 Share Posted May 21, 2008 an even better way, would be to check what the header type is: $filename = 'images/myimage.jpg'; $finfo = finfo_open(FILEINFO_MIME); // return mime type ala mimetype extension if(finfo_file($finfo, $filename) == 'image/jpeg'){ return TRUE; }else{ return FALSE; } Link to comment https://forums.phpfreaks.com/topic/106621-unable-to-readopen-uploaded-jpeg-files-from-digital-camera/#findComment-546497 Share on other sites More sharing options...
PFMaBiSmAd Posted May 21, 2008 Share Posted May 21, 2008 Do you have any error checking in your uploaded code so that you know the file was uploaded successfully? Does the $file parameter contain anything? Link to comment https://forums.phpfreaks.com/topic/106621-unable-to-readopen-uploaded-jpeg-files-from-digital-camera/#findComment-546503 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.