PHP的函數獲取圖片的寬高等信息


PHP的函數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.0 新加的 IMAGETYPE 常量對應。索引 3 是文本字符串,內容為“height="yyy" width="xxx"”,可直接用於 IMG 標記。
這是PHP官網的手冊:http://php.net/manual/en/function.get...
補充一個demo:

$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.'" />';
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM