How to detect faulty JPEG in PHP Issue with SOFn DQT or DHT JPEG marker missing before a JPEG SOS marker

0 votes

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?

Jun 7, 2022 in PHP by Kichu
• 19,040 points
869 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In PHP

0 votes
1 answer

In PHP, how to detect the execution is from CLI mode or through browser ?

Hello @kartik, Use the php_sapi_name() function. if (php_sapi_name() == "cli") { ...READ MORE

answered Oct 22, 2020 in PHP by Niroj
• 82,840 points
1,418 views
0 votes
1 answer

How to remove a child with a specific attribute, in SimpleXML for PHP?

Hii, Just unset the node: $str = <<<STR <a> ...READ MORE

answered Nov 5, 2020 in PHP by Niroj
• 82,840 points
4,294 views
0 votes
1 answer

What is a Cookie? How to create Cookies With PHP?

A cookie is often used to identify ...READ MORE

answered Feb 13, 2020 in PHP by Niroj
• 82,840 points
3,791 views
0 votes
1 answer

How to implement a callback in PHP?

Hello, Implementation of a callback is done like ...READ MORE

answered Apr 15, 2020 in PHP by Niroj
• 82,840 points
985 views
0 votes
1 answer

How to detect search engine bots with php?

Hello, You can checkout if it's a search ...READ MORE

answered Apr 20, 2020 in PHP by Niroj
• 82,840 points
1,354 views
0 votes
1 answer

How can I connect to a Tor hidden service using CURL in PHP?

Hello @kartik, I use Privoxy and cURL to scrape Tor ...READ MORE

answered May 19, 2020 in PHP by Niroj
• 82,840 points
5,319 views
+1 vote
2 answers

Scp Php files into server using gradle

Tru something like this: plugins { id ...READ MORE

answered Oct 11, 2018 in DevOps & Agile by lina
• 8,220 points
1,561 views
0 votes
1 answer

How do I create folder under an Amazon S3 bucket through PHP API?

Of Course, it is possible to create ...READ MORE

answered Apr 24, 2018 in AWS by anonymous
11,401 views
0 votes
1 answer

Failure uploading Image on AmazonS3 with PHP SDK

Try this, I took it out from ...READ MORE

answered May 4, 2018 in AWS by Cloud gunner
• 4,670 points
4,443 views
0 votes
1 answer

Trying to call AWS API via PHP

Try using AWS SDK for PHP, Link ...READ MORE

answered Jun 6, 2018 in AWS by Cloud gunner
• 4,670 points
1,742 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP