PHP code to detect whether png images are complete

WBOY
Release: 2016-07-29 08:43:46
Original
1277 people have browsed it

Copy code The code is as follows:


$filename = './D243375_0.png';
$filename = realpath($filename);
if (!file_exists($filename)) {
die("The picture does not exist~!");
}
$size = getimagesize ($filename);
$file_extension = strtolower(substr(strrchr($filename,"."),1));
if(" image/png" != $size['mime'] || $file_extension != "png"){
die("This is not a complete png picture");
}
$img = @imagecreatefrompng ($filename );
if($img){
ob_start("output_handler");
imagepng($img);
ob_end_flush();
}else{
die("The png graphic cannot be created correctly, please check whether the png graphic is intact ~");
}
function output_handler($img) {
header('Content-type: image/png');
header('Content-Length:'.strlen($img));
return $img;
}
?>

The above introduces the PHP code to detect whether the png image is complete, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template