PHP check JPG images for damage method _php tutorial

Source: Internet
Author: User
Can teach you the simplest way, for a JPG format picture, see whether the last two bytes are FFD9


If not, then it is generally not normal. In other formats, this method of judging is not applicable.
Normal JPG files start with FFD8, FFD9 end, if you lose the tail of the file, JPG can still be recognized, but will lose some of the image data.

--------
Of course, I said this is a simple judgment, may be lost before the end of the paragraph is just FFD9, but obviously still not correct, but basic enough. If the pursuit of rigor, then you have to read the JPEG format Specification document,
This does not belong to the knowledge category of PHP.

I've tried to determine the image format and pixels
You obviously can't, not deep enough, to be rigorous, you have to understand the storage of JPG.
As for the PHP tutorial of the GD library has a corresponding judgment function, I did not pay attention to, you can Google, I will not say more. You're welcome to study it and share it.

Share a PHP file that reads jpg

$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 "
n ";
echo "n";
echo "
n ";
}else{
echo "$k: $v
n ";
}
}

http://www.bkjia.com/PHPjc/632975.html www.bkjia.com true http://www.bkjia.com/PHPjc/632975.html techarticle can teach you the simplest way, for a JPG format picture, see whether the last two bytes is FFD9 if not, then generally is not normal. If it's a different format, this ...

  • 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.