龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

php 函数getimagesize获得图片的长宽等信息

时间:2014-11-26 02:23来源:网络整理 作者:网络 点击:
分享到:
函数getimagesize获得图片的长宽等信息 函数getimagesize返回一个具有四个单元的数组。索引 0 包含图像宽度的像素值,索引 1 包含图像高度的像素值。索引 2 是图像类型的标记:1 = GIF,2

函数getimagesize返回一个具有四个单元的数组。

索引 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。

这些标记与 PHP 4.3.0 新加的 IMAGETYPE 常量对应。索引 3 是文本字符串,内容为“height="yyy" width="xxx"”,可直接用于 IMG 标记。

$images_array = array("http://static.zend.com/img/logo.gif");
foreach($images_array as $image){
  list($width, $height, $type, $attr) = getimagesize($image);
  $new_height = (int)(192 / $width * $height);
  echo '<li><img src="'.$image.'" width="192px" height="'.$new_height.'" />';
}
//该片段来自于http://outofmemory.cn
精彩图集

赞助商链接