Is there a way to detect if an image has corrupt metadata in PHP?
Scenario: I have a JPEG file that seems to have some corrupt metadata, which causes problems for some software platforms. For example, when I try to load it with Adobe software I get this error: "Could not complete your request because a SOFn, DQT or DHT JPEG marker is missing before a JPEG SOS marker". However, the image looks fine in a browser, or in Microsoft Paint! My first suspicion was that it wasn't really a JPEG file, but the MIME-type is JPEG and the image data is JPEG according to various online tools.
In PHP I can create a new un-corrupt JPEG with the following code:
$bad_img = imagecreatefromjpeg($file);
list($w, $h, $type) = getimagesize($file);
$new_img = imagecreatetruecolor($w, $h);
imagecopyresampled($new_img, $bad_img, 0, 0, 0, 0, $w, $h, $w, $h);
I want to use this code only if the image is corrupted so is there a way to know that?