小白教程
所有教程
关于
Search
172.70.127.153
172.70.127.153
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Php getimagesize”的源代码
本页内容
上一节:
Php_gd_info
下一节:
Php_getimagesizefromstring
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:getimagesize()}}[[Category:PHP GD 图形处理函数参考手册|2]] = php getimagesize 函数 - 获取图像信息 = [[:Category:PHP GD 图形处理函数参考手册]] getimagesize() 函数用于获取图像大小及相关信息,成功返回一个数组,失败则返回 FALSE 并产生一条 E_WARNING 级的错误信息。 语法格式: <sample title="" desc="" lang="php" hererun="1"> array getimagesize ( string $filename [, array &$imageinfo ] ) </sample> getimagesize() 函数将测定任何 GIF,JPG,PNG,SWF,SWC,PSD,TIFF,BMP,IFF,JP2,JPX,JB2,JPC,XBM 或 WBMP 图像文件的大小并返回图像的尺寸以及文件类型及图片高度与宽度。 === 实例1:本地图片文件 === <sample title="" desc="" lang="php" hererun="1"> <?php list($width, $height, $type, $attr) = getimagesize("xiaobai-logo.png"); echo "宽度为:" . $width; echo "高度为:" . $height; echo "类型为:" . $type; echo "属性:" . $attr; ?> </sample> 以上实例输出结果为: <sample title="" desc="" lang="php" hererun="1"> 宽度为:290 高度为:69 类型为:3 属性:width="290" height="69" </sample> === 实例2:远程图片文件 === <sample title="" desc="" lang="php" hererun="1"> <?php $remote_png_url = 'http://www.xiaobai.wang/wp-content/themes/w3cschool.cc/assets/img/logo-domain-green2.png'; $img_data = getimagesize($remote_png_url); print_r($img_data ); ?> </sample> 以上实例输出结果为: <sample title="" desc="" lang="php" hererun="1"> Array ( [0] => 290 [1] => 69 [2] => 3 [3] => width="290" height="69" [bits] => 8 [mime] => image/png ) </sample> 返回结果说明 * 索引 0 给出的是图像宽度的像素值 * 索引 1 给出的是图像高度的像素值 * 索引 2 给出的是图像的类型,返回的是数字,其中1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 = PSD,6 = BMP,7 = TIFF(intel byte order),8 = TIFF(motorola byte order),9 = JPC,10 = JP2,11 = JPX,12 = JB2,13 = SWC,14 = IFF,15 = WBMP,16 = XBM * 索引 3 给出的是一个宽度和高度的字符串,可以直接用于 HTML 的 <image> 标签 * 索引 bits 给出的是图像的每种颜色的位数,二进制格式 * 索引 channels 给出的是图像的通道值,RGB 图像默认是 3 * 索引 mime 给出的是图像的 MIME 信息,此信息可以用来在 HTTP Content-type 头信息中发送正确的信息,如: header("Content-type: image/jpeg"); [[:Category:PHP GD 图形处理函数参考手册]]
返回至“
Php getimagesize
”。
上一节:
Php_gd_info
下一节:
Php_getimagesizefromstring