Home  >  Article  >  Backend Development  >  Detailed explanation of getimagesize example of obtaining the size of an image

Detailed explanation of getimagesize example of obtaining the size of an image

怪我咯
怪我咯Original
2017-07-06 10:29:532353browse

This article mainly introduces the method of getimagesize to obtain the picture size. The example describes the implementation method of getimagesize to obtain the size, format and other parameters of the picture. It has certain reference value and friends in need can refer to it. Next

The example in this article describes the method of getimagesize to obtain the image size. Share it with everyone for your reference. The details are as follows:

php has a ready-made function getimagesize for getting the size of the image, code example:

The code is as follows:

<?php 
/* 1.jpg为你想获得其尺寸的图片 */ 
$arr = getimagesize("1.jpg"); 
/** 
 * 这里$arr为一个数组类型 
 * $arr[0] 为图像的宽度 
 * $arr[1] 为图像的高度 
 * $arr[2] 为图像的格式,包括jpg、gif和png等 
 * $arr[3] 为图像的宽度和高度,内容为 width="xxx" height="yyy" 
 */ 
/* 以下两行代码输出的内容都是一样的 */ 
echo "<img src="1.jpg" $arr[3] alt="" />"; 
echo "<img src="1.jpg" width="$arr[0]" height="$arr[1]" alt="" />"; 
?>
<img src="1.jpg" width="xxx" height="yyy" alt="" /> 
<img src="1.jpg" width="xxx" height="yyy" alt="" />

The above is the detailed content of Detailed explanation of getimagesize example of obtaining the size of an image. For more information, please follow other related articles on the PHP Chinese website!

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