array getimagesize ( string filename [, array &imageinfo ] )
getimagesize() 函数将测定任何 GIF,JPG,PNG,SWF,SWC,PSD,TIFF,BMP,IFF,JP2,JPX,JB2,JPC,XBM 或 WBMP 图像文件的大小并返回图像的尺寸以及文件类型和一个可以用于普通 HTML 文件中 IMG 标记中的 height/width 文本字符串。
Failed 返回 false.
Example
1.本地图片:
<?php
$image_size=getimagesize('image.jpg');
var_dump($image_size);
?>
//output
array (size=7)
0 => int 639
1 => int 149
2 => int 1 //(拿到的是真实的extention,尽管图片被改了后缀名)
3 => string 'width="639" height="149"' (length=24)
'bits' => int 8
'channels' => int 3
'mime' => string 'image/gif' (length=9)
2.上传图片:
<!--upload.html-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>上传图片</title>
</head>
<body>
<form enctype="multipart/form-data" method="post" action="upload.php">
<input name="myImage" type="file" />
<input type="submit" value="submit" id="submit" />
</form>
</body>
</html>
//upload.php
<?php
$uploadFile=$_FILES['myImage']['tmp_name'];
list($width, $height, $type) = getimagesize($uploadFile);
?>
output
index | remark |
---|---|
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 | 文本字符串:内容为’height=”yyy” width=”xxx”’,可直接用于 IMG 标记 |
bits | 图像深度 |
channels | 图像的色彩通道,对于 RGB 图像其值为 3,对于 CMYK 图像其值为 4 |
mime | 参数mime,内容为:’image/gif’。此信息可以用来在 HTTP Content-type 头信息中发送正确的信息 |