getimagesize
(PHP 3, PHP 4 )getimagesize -- Get the size of an image
Description
array getimagesize ( string filename [, array imageinfo])The getimagesize() function will determine the size of any GIF, JPG, PNG, SWF, SWC, PSD, TIFF, BMP or IFF image file and return the dimensions along with the file type and a height/width text string to be used inside a normal HTML IMG tag. Returns an array with 4 elements. Index 0 contains the width of the image in pixels. Index 1 contains the height. Index 2 a flag indicating the type of the image. 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. These values correspond to the IMAGETYPE constants that were added in PHP 4.3. 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. getimagesize (file)<?php
$size = getimagesize ("img/flag.jpg");
echo "<img src=\"img/flag.jpg\" {$size[3]}>";
?>
Example 2. getimagesize (URL)<?php $size = getimagesize ("http://www.example.com/gifs/logo.gif"); ?>
With JPG images, two extras index 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. Since PHP 4.3 bits and channels are present for other image types, too. But these values or there presence can be a bit confusing. As example GIF allways uses 3 channels per pixel but the number of bits per pixel cannot be computed for an animated GIF with a global colortable. Some formats may contain no image or multiple images. In such cases GetImageSize might not be able to determine the size and returns zero for width and height. Since PHP 4.3 GetImageSize() does also return the additional mime that receives the mime-type of the image. This information can be used to deliver images with correct http Content-type header if this is unknown: Example 3. getimagesize and mime-type<?php
$size = getimagesize ($filename);
$fp=fopen($filename, "rb");
if ($size && $fp) {
header("Content-type: {$size['mime']}");
fpassthru($fp);
exit;
} else // error
?>If accessing the filename image is impossible, or if it isn't a valid picture, getimagesize() will return NULL and generate a warning. The optional imageinfo parameter allows you to extract some extended information from the image file. Currently this will return the different JPG APP ers in an associative Array. Some Programs use these APP ers to embed text information in images. A very common one is to embed IPTC http://www.iptc.org/ information in the APP13 er. You can use the iptcparse() function to parse the binary APP13 er into something readable. Example 4. getimagesize returning IPTC<?php
$size = getimagesize ("testimg.jpg",&$info);
if (isset ($info["APP13"])) {
$iptc = iptcparse ($info["APP13"]);
var_dump ($iptc);
}
?>Note: TIFF support was added in PHP 4.2. JPEG2000 support will be added in PHP 4.3. This function does not require the GD image library. See also image_type_to_mime_type(), exif_imagetype(), exif_read_data() and exif_thumbnail(). URL support was added in PHP 4.0.5
(PHP 3, PHP 4 )getimagesize -- Get the size of an image
Description
array getimagesize ( string filename [, array imageinfo])The getimagesize() function will determine the size of any GIF, JPG, PNG, SWF, SWC, PSD, TIFF, BMP or IFF image file and return the dimensions along with the file type and a height/width text string to be used inside a normal HTML IMG tag. Returns an array with 4 elements. Index 0 contains the width of the image in pixels. Index 1 contains the height. Index 2 a flag indicating the type of the image. 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. These values correspond to the IMAGETYPE constants that were added in PHP 4.3. 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. getimagesize (file)<?php
$size = getimagesize ("img/flag.jpg");
echo "<img src=\"img/flag.jpg\" {$size[3]}>";
?>
Example 2. getimagesize (URL)<?php $size = getimagesize ("http://www.example.com/gifs/logo.gif"); ?>
With JPG images, two extras index 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. Since PHP 4.3 bits and channels are present for other image types, too. But these values or there presence can be a bit confusing. As example GIF allways uses 3 channels per pixel but the number of bits per pixel cannot be computed for an animated GIF with a global colortable. Some formats may contain no image or multiple images. In such cases GetImageSize might not be able to determine the size and returns zero for width and height. Since PHP 4.3 GetImageSize() does also return the additional mime that receives the mime-type of the image. This information can be used to deliver images with correct http Content-type header if this is unknown: Example 3. getimagesize and mime-type<?php
$size = getimagesize ($filename);
$fp=fopen($filename, "rb");
if ($size && $fp) {
header("Content-type: {$size['mime']}");
fpassthru($fp);
exit;
} else // error
?>If accessing the filename image is impossible, or if it isn't a valid picture, getimagesize() will return NULL and generate a warning. The optional imageinfo parameter allows you to extract some extended information from the image file. Currently this will return the different JPG APP ers in an associative Array. Some Programs use these APP ers to embed text information in images. A very common one is to embed IPTC http://www.iptc.org/ information in the APP13 er. You can use the iptcparse() function to parse the binary APP13 er into something readable. Example 4. getimagesize returning IPTC<?php
$size = getimagesize ("testimg.jpg",&$info);
if (isset ($info["APP13"])) {
$iptc = iptcparse ($info["APP13"]);
var_dump ($iptc);
}
?>Note: TIFF support was added in PHP 4.2. JPEG2000 support will be added in PHP 4.3. This function does not require the GD image library. See also image_type_to_mime_type(), exif_imagetype(), exif_read_data() and exif_thumbnail(). URL support was added in PHP 4.0.5
解决方案 »
- 新手求教EclipsePHP Studio的配置
- mysql_fetch_array(): supplied argument is not a valid mysql result resource
- 关于html与php混写的语法问题
- 实在不知道怎么错了,各位帮忙看看
- PHP 删除上传后文件的问题。
- 提供了10G的FTP空间,欢迎大家上传好的资源一起分享。
- 怎样获取另外一个文件中的变量,不用require或include
- 怎么输入随机的日期就得到星期几
- 不爽,散分!项目要做好了对方居然飞单。
- 想好久,怎么能在数据库中查询出出现最多的中文
- 一个关于表单提交的问题,高分,在线等候.
- 怎样做网站?如何设计?
其中0,1对于图片的width,height数字
3的值对于图片格式,gif 为1,jpg为2,png为3
4对应的是一个字符串,形式为:width="" height=""
这个函数可以很轻松的得到每个图片的高和宽