getimagesize

说明

array getimagesize ( string filename [, array imageinfo])

返回一个具有四个单元的数组。索引 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 新加的 IMAGETYPE 常量对应。索引 3 是文本字符串,内容为“height="yyy" width="xxx"”,可直接用于 IMG 标记。

例子 1. getimagesize (file)

<?php
list($width, $height, $type, $attr) = getimagesize("img/flag.jpg");
echo "<img src=\"img/flag.jpg\" $attr>";
?>


例子 2. getimagesize (URL)

<?php
$size = getimagesize("http://www.baidu.com/img/baidu_sylogo1.gif");

// if the file name has space in it, encode it properly

print_r($size);  
Array
(
    [0] => 270
    [1] => 129
    [2] => 1
    [3] => width="270" height="129"
    [bits] => 4
    [channels] => 3
    [mime] => image/gif
)

?>

你可能感兴趣的:(getimagesize)