欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php中几个简单图片判断函数_PHP教程

程序员文章站 2022-03-09 13:11:58
...
int exif_imagetype ( string $filename )
1 imagetype_gif
2 imagetype_jpeg
3 imagetype_png
4 imagetype_swf
5 imagetype_ps教程d
6 imagetype_bmp
7 imagetype_tiff_ii (intel byte order)
8 imagetype_tiff_mm (motorola byte order)
9 imagetype_jpc
10 imagetype_jp2
11 imagetype_jpx
12 imagetype_jb2
13 imagetype_swc
14 imagetype_iff
15 imagetype_wbmp
16 imagetype_xbm

*/
$img="image.gif"; //定义文件
if(exif_imagetype($img)!=imagetype_gif) //判断文件类型
{
echo "指定的图片不是gif图片"; //输出结果
}
else
{
echo "指定的图片是gif图片";
}

/*
array exif_read_data ( string $filename [, string $sections = null [, bool $arrays = false [, bool $thumbnail = false ]]] )

*/

echo "test1.jpg:
n"; //输出文件名
$exif=exif_read_data('tests/test1.jpg','ifd0'); //读取文件1信息
//根据结果判断
echo $exif===false ? "no header data found.
n":"image contains headers
n";
$exif=exif_read_data('tests/test2.jpg',0,true); //读取文件2信息
echo "test2.jpg:
n"; //输出文件名
foreach($exif as $key=>$section) //循环读取信息
{
foreach($section as $name=>$val)
{
echo "$key.$name:$val
n";
}
}
/*
test1.jpg:
no header data found.
test2.jpg:
file.filename: test2.jpg
file.filedatetime: 1017666176
file.filesize: 1240
file.filetype: 2
file.sectionsfound: any_tag, ifd0, thumbnail, comment
computed.html: width="1" height="1"
computed.height: 1
computed.width: 1
computed.iscolor: 1
computed.byteordermotorola: 1
computed.usercomment: exif test image.
computed.usercommentencoding: ascii
computed.copyright: photo (c) m.boerger, edited by m.boerger.
computed.copyright.photographer: photo (c) m.boerger
computed.copyright.editor: edited by m.boerger.
ifd0.copyright: photo (c) m.boerger
ifd0.usercomment: ascii
thumbnail.jpeginterchangeformat: 134
thumbnail.jpeginterchangeformatlength: 523
comment.0: comment #1.
comment.1: comment #2.
comment.2: comment #3end
thumbnail.jpeginterchangeformat: 134
thumbnail.thumbnail.height: 1
thumbnail.thumbnail.height: 1


//*/

$index="1"; //定义索引
$string=exif_tagname($index); //获得图像索引的头信息
echo $string; //输出结果

//

if(array_key_exists('file',$_request))
{
$image=exif_thumbnail($_request['file'],$width,$height,$type); //取得文件的缩略图
}
else //如果数组不存在相应的键值
{
$image=false; //返回错误
}
if($image!==false) //如果返回true
{
header("content-type:".image_type_to_mime_type($type)); //发送头文件
echo $image; //输出缩略图
exit; //结束php教程代码
}
else //如果返回错误
{
echo "no thumbnail available"; //输出信息
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/632997.htmlTechArticleint exif_imagetype ( string $filename ) 1 imagetype_gif 2 imagetype_jpeg 3 imagetype_png 4 imagetype_swf 5 imagetype_ps教程d 6 imagetype_bmp 7 imagetype_tiff_ii (intel byte order...