Home >Backend Development >PHP Tutorial >PHP method to check whether jpg image is damaged_PHP tutorial

PHP method to check whether jpg image is damaged_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:46:171368browse

I can teach you the simplest way. For pictures in JPG format, check whether the last two bytes are FFD9


If not, it's generally not normal. If it is in other formats, this judgment method does not apply.
Normal JPG files start with FFD8 and end with FFD9. If the tail of the file is lost, the JPG can still be recognized, but part of the image data will be lost.

--------
Of course, what I am talking about is just a simple judgment. It may be that the end of the paragraph before the loss happens to be FFD9, but it is obviously still incorrect, but it is basically enough. If you pursue rigor, then you have to read the JPEG format specification document,
This is no longer within the scope of PHP knowledge.

I tried to determine the image format and pixels
You are obviously not good at this. It is not in-depth enough. To be rigorous, you must have a deep understanding of JPG storage.
As for whether the GD library of the PHP tutorial has a corresponding judgment function, I have not paid attention to it. You can google it, so I won’t say more. You are welcome to share it after researching 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";
}
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632975.htmlTechArticle can teach you the simplest way. For pictures in JPG format, check whether the last two bytes are FFD9 If not, then it is generally abnormal. If it is in other formats, this...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn