Home >Backend Development >PHP Tutorial >php getimagesize function gets image width and height_PHP tutorial

php getimagesize function gets image width and height_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 10:59:151222browse

If you want to use PHP to get the height and width of an image, we can directly use the getimagesize function in PHP to operate it. Let me introduce to you in detail how to use the getimagesize function. ​

The getimagesize() function will determine the size of any GIF, JPG, PNG, SWF, SWC, PSD, TIFF, BMP, IFF, JP2, JPX, JB2, JPC, XBM or WBMP image file and return the dimensions of the image and the file type and a height/width text string that can be used in IMG tags in normal HTML files.

The code is as follows Copy code
 代码如下 复制代码

$arr = getimagesize("http://www.php100.com/html/php/hanshu/2013/0905/1.jpg");

/**
 * 这里$arr为一个数组类型
 * $arr[0] 为图像的宽度
 * $arr[1] 为图像的高度
 * $arr[2] 为图像的格式,包括jpg、gif和png等
 * $arr[3] 为图像的宽度和高度,内容为 width="xxx" height="yyy"
 */

/* 以下两行代码输出的内容都是一样的 */
echo "";
echo "";
?>

$arr = getimagesize("http://www.php100.com/html/php/hanshu/2013/0905/1.jpg");

/**
* Here $arr is an array type
* $arr[0] is the width of the image
* $arr[1] is the height of the image
* $arr[2] is the format of the image, including jpg, gif, png, etc.
* $arr[3] is the width and height of the image, and the content is width="xxx" height="yyy"
​*/
 代码如下 复制代码



/* The following two lines of code output the same content */
echo "";
echo "";
?>

The above php code is interpreted as the content is:

The code is as follows Copy code
 代码如下 复制代码

list($width, $height, $type, $attr) = getimagesize("http://www.php100.com/html/php/hanshu/2013/0905/img/flag.jpg");
echo "php getimagesize function gets image width and height_PHP tutorial";
?>




Example

Example #1 getimagesize(file) http://www.bkjia.com/PHPjc/445637.htmlwww.bkjia.comtrue
http: //www.bkjia.com/PHPjc/445637.html
TechArticle
If you want to use php to get the height and width of the image, we can directly use the getimagesize function in php to operate, as follows Let me introduce to you in detail how to use the getimagesize function. getima...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn