成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導(dǎo)航首頁 ? 技術(shù)教程 ? PHP:getimagesize()的用法_GD庫圖像處理函數(shù)
全站頭部文字 我要出現(xiàn)在這里
PHP:getimagesize()的用法_GD庫圖像處理函數(shù) 922 2023-12-15   

getimagesize

(PHP 4, PHP 5)

getimagesize — 取得圖像大小

說明

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

getimagesize() 函數(shù)將測定任何 GIF,JPG,PNG,SWF,SWC,PSD,TIFF,BMP,IFF,JP2,JPX,JB2,JPC,XBM 或 WBMP 圖像文件的大小并返回圖像的尺寸以及文件類型和一個可以用于普通 HTML 文件中 IMG 標記中的 height/width 文本字符串。

如果不能訪問 filename 指定的圖像或者其不是有效的圖像,getimagesize() 將返回 FALSE 并產(chǎn)生一條 E_WARNING 級的錯誤。

Note:

對 JPC,JP2,JPX,JB2,XBM 和 WBMP 的支持自 PHP 4.3.2 起可用。對 SWC 的支持自 PHP 4.3.0 起可用。對 TIFF 的支持是 PHP 4.2.0 添加的。

Note: JPEG 2000 支持是 PHP 4.3.2 添加的。注意 JPC 和 JP2 可以有不同的色彩深度的成分。此情況下,“bits”的值是碰到的最高的位深度。此外,JP2 文件可能包含有多個 JPEG 2000 代碼流,此情況下,getimagesize() 返回此文件頂層中碰到的第一個代碼流的值。

Note: 本函數(shù)不需要 GD 圖像庫。

返回一個具有四個單元的數(shù)組。索引 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 常量對應(yīng)。索引 3 是文本字符串,內(nèi)容為“height="yyy" width="xxx"”,可直接用于 IMG 標記。

Example #1 getimagesize(文件)

<?php
list($width, $height, $type, $attr) = getimagesize("img/flag.jpg");
echo "<img src="http://www.gimoo.net/t/1405/img/flag.jpg" $attr>";
?>

URL 支持是 PHP 4.0.5 添加的。

Example #2 getimagesize(URL)

<?php
$size = getimagesize("http://www.example.com/gifs/logo.gif");

// if the file name has space in it, encode it properly
$size = getimagesize("http://www.example.com/gifs/lo%20go.gif");

?>

對于 JPG 圖像,還會多返回兩個索引:channels 和 bits。channels 對于 RGB 圖像其值為 3,對于 CMYK 圖像其值為 4。bits 是每種顏色的位數(shù)。

自 PHP 4.3.0 起,bits 和 channels 對于其它圖像類型也存在。但是這些值可能會把人搞糊涂。例如,GIF 總是對每個像素使用 3 個 channel,但是對于動畫 GIF 來說每個像素的位數(shù)無法通過全局顏色表計算出來。

某些格式可能不包含圖像或者包含多個圖像。此種情況下,getimagesize() 可能不能用來準確測定圖像的大小。此時 getimagesize() 將返回零作為寬度和高度。

自 PHP 4.3.0 起,getimagesize() 還會返回額外的參數(shù) mime,符合該圖像的 MIME 類型。此信息可以用來在 HTTP Content-type 頭信息中發(fā)送正確的信息:

Example #3 getimagesize() 和 MIME 類型

<?php
$size = getimagesize($filename);
$fp=fopen($filename, "rb");
if ($size && $fp) {
  header("Content-type: {$size['mime']}");
  fpassthru($fp);
  exit;
} else {
  // error
}
?>

可選的 imageinfo 參數(shù)允許從圖像文件中提取一些擴展信息。目前,這將以一個關(guān)聯(lián)數(shù)組返回不同的 JPG APP 標識。某些程序用這些 APP 標識來在圖像中嵌入文本信息。一個非常常見的是 APP13 標識中嵌入的 IPTC » http://www.iptc.org/ 信息??梢杂?iptcparse() 函數(shù)來將二進制的 APP13 標識解析為可讀的信息。

Example #4 getimagesize() 返回 IPTC

<?php
$size = getimagesize("testimg.jpg", &$info);
if (isset($info["APP13"])) {
    $iptc = iptcparse($info["APP13"]);
    var_dump($iptc);
}
?>

參見 image_type_to_mime_type(),exif_imagetype(),exif_read_data() 和 exif_thumbnail()。

參數(shù)

filename

This parameter specifies the file you wish to retrieve information about. It can reference a local file or (configuration permitting) a remote file using one of the supported streams.

imageinfo

This optional parameter allows you to extract some extended information from the image file. Currently, this will return the different JPG APP markers as an associative array. Some programs use these APP markers to embed text information in images. A very common one is to embed » IPTC information in the APP13 marker. You can use the iptcparse() function to parse the binary APP13 marker into something readable.

返回值

Returns an array with 7 elements.

Index 0 and 1 contains respectively the width and the height of the image.

Note:

Some formats may contain no image or may contain multiple images. In these cases, getimagesize() might not be able to properly determine the image size. getimagesize() will return zero for width and height in these cases.

Index 2 is one of the IMAGETYPE_XXX constants indicating the type of the image.

Index 3 is a text string with the correct height="yyy" width="xxx" string that can be used directly in an IMG tag.

mime is the correspondant MIME type of the image. This information can be used to deliver images with the correct HTTP Content-type header:

Example #5 getimagesize() and MIME types

<?php
$size = getimagesize($filename);
$fp = fopen($filename, "rb");
if ($size && $fp) {
    header("Content-type: {$size['mime']}");
    fpassthru($fp);
    exit;
} else {
    // error
}
?>

channels will be 3 for RGB pictures and 4 for CMYK pictures.

bits is the number of bits for each color.

For some image types, the presence of channels and bits values can be a bit confusing. As an example, GIF always uses 3 channels per pixel, but the number of bits per pixel cannot be calculated for an animated GIF with a global color table.

On failure, FALSE is returned.

錯誤/異常

If accessing the filename image is impossible, or if it isn't a valid picture, getimagesize() will generate an error of level E_WARNING. On read error, getimagesize() will generate an error of level E_NOTICE.

更新日志

版本 說明 5.3.0 Added icon support. 5.2.3 Read errors generated by this function downgraded to E_NOTICE from E_WARNING. 4.3.2 Support for JPC, JP2, JPX, JB2, XBM, and WBMP became available. 4.3.2 JPEG 2000 support was added for the imageinfo parameter. 4.3.0 bits and channels are present for other image types, too. 4.3.0 mime was added. 4.3.0 Support for SWC and IFF was added. 4.2.0 Support for TIFF was added. 4.0.6 Support for BMP and PSD was added. 4.0.5 URL support was added.

范例

Example #6 getimagesize() example

<?php
list($width, $height, $type, $attr) = getimagesize("img/flag.jpg");
echo "<img src="http://www.gimoo.net/t/1405/img/flag.jpg" $attr alt="getimagesize() example" />";
?>

Example #7 getimagesize (URL)

<?php
$size = getimagesize("http://www.example.com/gifs/logo.gif");

// if the file name has space in it, encode it properly
$size = getimagesize("http://www.example.com/gifs/lo%20go.gif");

?>

Example #8 getimagesize() returning IPTC

<?php
$size = getimagesize("testimg.jpg", $info);
if (isset($info["APP13"])) {
    $iptc = iptcparse($info["APP13"]);
    var_dump($iptc);
}
?>

注釋

Note:

此函數(shù)不需要 GD 圖象庫。

參見

image_type_to_mime_type() - 取得 getimagesize,exif_read_data,exif_thumbnail,exif_imagetype 所返回的圖像類型的 MIME 類型 exif_imagetype() - 判斷一個圖像的類型 exif_read_data() - 從 JPEG 或 TIFF 文件中讀取 EXIF 頭信息 exif_thumbnail() - 取得嵌入在 TIFF 或 JPEG 圖像中的縮略圖


主站蜘蛛池模板: 分手男女| 温暖的弦电视剧全集免费观看高清| 寒战2剧情解析| 时尚购物| yy五项滚刀骂人套词| 安息2| 小孩几个月会翻身| 海霞电影| 重温经典节目预告| you are my sunshine简谱| 免费看黄网址| 广西地图全图可放大| 秀人网 官网门户免费| 板谷由夏| 2024生物中考真题试卷| 看黄在线看| 斯科| 乱世危情电视剧演员表| 一个月经代表七个版本| 新娘大作战电影免费观看完整版| 单招在线咨询| 麦当娜·西科尼| 铁血战士电影| 50000蛋币兑换码2025年有效| 外道学园| 分部分项工程验收记录表| overwatch| 大尺度床戏韩国| 雪中悍刀行第一季电视剧免费观看| 国家励志奖学金个人主要事迹1500字 | 欧美日韩欧美日韩| 又大又肥又圆的白屁股| 吴雪雯| 一夜惊喜 电影| 快乐读书吧1-6年级推荐书目| 李采潭全部作品百度| 脚部反射区图解大全高清| 达斯汀·克莱尔| 让娜迪尔曼| 萱草花合唱谱二声部完整版| 568b水晶头接法图|

?。?!站長長期在線接!?。?/p>

網(wǎng)站、小程序:定制開發(fā)/二次開發(fā)/仿制開發(fā)等

各種疑難雜癥解決/定制接口/定制采集等

站長微信:lxwl520520

站長QQ:1737366103