Home > Backend Development > PHP Tutorial > php获取图片尺寸(宽度,高度)方法

php获取图片尺寸(宽度,高度)方法

WBOY
Release: 2016-06-20 13:02:39
Original
1252 people have browsed it

本文详细介绍PHP获取图片尺寸(宽度,高度)的函数,即getimagesize()函数。

语法:

array getimagesize( string filename [, array &imageinfo] )
Copy after login

功能:

getimagesize()函数将测定任何GIF,JPG,PNG,SWF,SWC,PSD,TIFF,BMP,IFF,JP2,JPX,JB2,JPC,XBM或WBMP图像文件并返回文件的大小,尺寸,文件类型以及一个可以用于普通HTML文件中标记中的 height/width 文本字符串。

如果不能访问指定的图像或者其不是有效的图像,getimagesize()将返回FALSE并产生一条E_WARNING级的错误。

注:

(1)本函数不需要 GD 图像库支持。

(2)该函数除了可以获取本地图片或者Flash的相关信息外还可以直接用来获取远程的。

示例:

<p><?php</p>list($width,$height,$type,$attr)=getimagesize("http://www.phpernote.com/images/logo.gif");<br />echo "Image width ".$width;<br />echo "<br/>";<br />echo "Image height ".$height;<br />echo "<br/>";<br />echo "Image type ".$type;<br />echo "<br/>";<br /><p>echo "Attribute ".$attr;</p>
Copy after login

输出信息如下:

Image width 200

Image height 55
Image type 1

Image attribute width="200" height="55"

其中图片类型的参数参考如下:

 
1 = GIF  5 = PSD  9 = JPC  13 = SWC
 
2 = JPG  6 = BMP  10 = JP2  14 = IFF
 
3 = PNG  7 = TIFF(intel byte order)  11 = JPX  15 = WBMP
 
4 = SWF  8 = TIFF(motorola byte order)  12 = JB2  16 = XBM


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