php getimagebinary,php 获取图片属性 getimagesize

Description

array getp_w_picpathsize ( string filename [, array &p_w_picpathinfo] )

The getp_w_picpathsize() function will determine the size of any GIF, JPG, PNG, SWF, SWC, PSD, TIFF, BMP, IFF,JP2, JPX, JB2, JPC, XBM, or WBMP p_w_picpath file and return the dimensions along with the file type and a height/width text string to be used inside a normal HTML  tag.

If accessing the filename p_w_picpath is impossible, or if it isn't a valid picture, getp_w_picpathsize() will return FALSE and generate an error of level E_WARNING.

Note:Support for JPC, JP2, JPX, JB2, XBM, and WBMP became available in PHP 4.3.2. Support for SWC exists as of PHP 4.3.0 and TIFF support was added in PHP 4.2.0

Note:JPEG 2000 support was added in PHP 4.3.2. Note that JPC and JP2 are capable of having components with different bit depths. In this case, the value for "bits" is the highest bit depth encountered. Also, JP2 files may contain multiple JPEG 2000 codestreams. In this case, getp_w_picpathsize() returns the values for the first codestream it encounters in the root of the file.

Note:The getp_w_picpathsize() function does not require the GD p_w_picpath library.

Returns an array with 4 elements. Index 0 contains the width of the p_w_picpath in pixels. Index 1 contains the height. Index 2 is a flag indicating the type of the p_w_picpath: 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. These values correspond to the IMAGETYPE constants that were added in PHP 4.3.0. Index 3 is a text string with the correct height="yyy" width="xxx" string that can be used directly in an IMG tag.

Example 1. getp_w_picpathsize (file)

echo"\"getp_w_picpathsize()";?>

URL support was added in PHP 4.0.5

Example 2. getp_w_picpathsize (URL)

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

With JPG p_w_picpaths, two extra indexes are returned: channels and bits. channels will be 3 for RGB pictures and 4 for CMYK pictures. bits is the number of bits for each color.

Beginning with PHP 4.3.0, bits and channels are present for other p_w_picpath types, too. However, the presence of these 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.

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

Beginning with PHP 4.3.0, getp_w_picpathsize() also returns an additional parameter, mime, that corresponds with the MIME type of the p_w_picpath. This information can be used to deliver p_w_picpaths with correct HTTP Content-type headers:

Example 3. getp_w_picpathsize() and MIME types

$size=getp_w_picpathsize($filename);$fp=fopen($filename,"rb");

if ($size&&$fp) {header("Content-type: {$size['mime']}");fpassthru($fp);

exit;

} else {// error}?>

The optional p_w_picpathinfo parameter allows you to extract some extended information from the p_w_picpath 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 p_w_picpaths. A very common one is to embed IPTC http://www.iptc.org/information in the APP13 marker. You can use the iptcparse() function to parse the binary APP13 marker into something readable.

Example 4. getp_w_picpathsize() returning IPTC

$size=getp_w_picpathsize("testimg.jpg",$info);

if (isset($info["APP13"])) {$iptc=iptcparse($info["APP13"]);var_dump($iptc);

}?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值