getimagesize Get Picture Size Instance

  • 2021-08-03 09:47:57
  • OfStack

In this paper, an example is given to describe the method of obtaining picture size by getimagesize. Share it for your reference. The details are as follows:

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

<?php 
/* 1.jpg For the picture you want to get its size */
$arr = getimagesize("1.jpg");
/**
 * Here $arr For 1 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 And png Etc
 * $arr[3] Is the width and height of the image, and the content is width="xxx" height="yyy"
 */
/* The output of the following two lines of code is 1 Like */
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="" />

I hope this article is helpful to everyone's PHP programming.


Related articles: