Php: How to check whether the jpg image is damaged

Source: Internet
Author: User

The simplest method is to check whether the last two bytes are FFD9 for JPG images.


If not, it is generally abnormal. If it is another format, this method is not applicable.
Normal JPG files start with FFD8 and end with FFD9. If the end of the file is lost, JPG files can still be recognized, but part of the image data will be lost.

--------
Of course, what I'm talking about is just a simple judgment. I may lose the end of the previous section, which is exactly FFD9, but obviously it is still incorrect, but it is basically enough. If you are pursuing rigor, you must read the JPEG format standard document,
This is no longer part of PHP knowledge.

I tried to determine the image format and pixels.
Obviously you are not good at this. If you are not thorough enough, you must have an in-depth understanding of JPG storage.
As to whether the GD library in the php tutorial has a corresponding judgment function, I have not paid much attention to it. You can google it, so I will not say much about it. Welcome to share it after research.

Share a PHP file that reads jpg files

$ Adress = "IMG_XXX.JPG ";
$ Exif = read_exif_data ($ adress );
While (list ($ k, $ v) = each ($ exif )){
If ($ k = "Thumbnail "){
$ Fp = fopen ("/www/home/image/Thumbnail $ adress ",
'A ');
Fwrite ($ fp, $ v );
Fclose ($ fp );
Echo "<br/> n ";
Echo "n ";
Echo "<br/> n ";
} Else {
Echo "$ k: $ v <br/> n ";
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.