Jump to content

Unable to read/open uploaded JPEG files from digital camera


scooter41

Recommended Posts

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

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;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.