php getimagesize 上传图片的长度和宽度检测代码

2019-04-09 20:20:32王旭

<?php
$size = getimagesize($filename);
$fp=fopen($filename, "rb");
if ($size && $fp) {
header("Content-type: {$size['mime']}");
fpassthru($fp);
exit;
} else {
// error
}
?>

可选的 imageinfo 参数允许从图像文件中提取一些扩展信息。目前,这将以一个关联数组返回不同的 JPG APP 标识。某些程序用这些 APP 标识来在图像中嵌入文本信息。一个非常常见的是 APP13 标识中嵌入的 IPTC » http://www.iptc.org/ 信息。可以用 iptcparse() 函数来将二进制的 APP13 标识解析为可读的信息。
Example #4 getimagesize() 返回 IPTC

<?php
$size = getimagesize("testimg.jpg", &$info);
if (isset($info["APP13"])) {
$iptc = iptcparse($info["APP13"]);
var_dump($iptc);
}
?>


php 有个图片GD库getimagesize()函数。
有个函数是获取图片的基本信息。
getimagesize()
$img=getimagesize('图片源');
宽度为=$img[0];
高度为=$img[1];
格式为=$img[2];
如果你要简单的话可以更简单如

$picpath = '//www.jb51.net/images/logo.gif';
$array = getimagesize($picpath);
print_r( $array );
echo '图片宽度为'.$array[0];
echo '图片高度为'.$array[1];
echo '图片格式为'.$array[2];

//再一个利用getimagesize显示缩略图的代码

function show_thumbnail($file)
{
$max = 200 // Max. thumbnail width and height
$size = getimagesize($file);
if ( $size[0] <= $max && $size[1] <= $max )
{
$ret = '<img src="'.$file.'" '.$size[3].' border="0">';
}
else
{
$k = ( $size[0] >= $size[1] ) ? $size[0] / $max : $size[1] / $max;
$ret = '<a href="javascript教程:;" onClick="window.open('image.php?img=';
$ret .= $file.'','','width='.$size[0];
$ret .= ',height='.$size[1].'')">';
$ret .= '<img src="'.$file.'" width="'.floor($size[0]/$k).'" height="'.floor($size[1]/$k).'" border="0" alt="View full-size image"></a>';
}
return $ret;
}
相关文章 大家在看