php擷取圖片尺寸(寬度,高度)方法

來源:互聯網
上載者:User
本文詳細介紹PHP擷取圖片尺寸(寬度,高度)的函數,即getimagesize()函數。

文法:

array getimagesize( string filename [, array &imageinfo] )

功能:

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的相關資訊外還可以直接用來擷取遠端。

樣本:

list($width,$height,$type,$attr)=getimagesize("http://www.phpernote.com/images/logo.gif");
echo "Image width ".$width;
echo "
";
echo "Image height ".$height;
echo "
";
echo "Image type ".$type;
echo "
";

echo "Attribute ".$attr;

輸出資訊如下:

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
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.