php-获取图像尺寸

这个问题已经在这里有了答案:

  • 如何使用PHP查找图像的宽度?                                     5个答案

我有图片的网址,例如array([h]=> 200, [w]=>100)

如何获得数组的尺寸,例如array([h]=> 200, [w]=>100) (height=200, width=100)

James asked 2020-02-21T15:20:55Z
3个解决方案
114 votes

您可以使用getimagesize函数,如下所示:

list($width, $height) = getimagesize('path to image');
echo "width: " . $width . "<br />";
echo "height: " .  $height;
Sarfraz answered 2020-02-21T15:21:12Z
39 votes

使用getimagesize函数,我们还可以获得特定图像的这些属性,

<?php

list($width, $height, $type, $attr) = getimagesize("image_name.jpg");

echo "Width: " .$width. "<br />";
echo "Height: " .$height. "<br />";
echo "Type: " .$type. "<br />";
echo "Attribute: " .$attr. "<br />";

//Using array
$arr = array('h' => $height, 'w' => $width, 't' => $type, 'a' => $attr);
?>


这样的结果-

宽:200
身高:100
类型2
属性:width ='200'height ='100'


图片类型请考虑-

1 = GIF
2 = JPG
3 = PNG
4 = SWF
5 = PSD
6 = BMP
7 = TIFF(英特尔字节顺序)
8 = TIFF(摩托罗拉字节顺序)
9 = JPC
10 = JP2
11 = JPX
12 = jba
13 = SWC
14 = IFF
15 = WBMP
16 = XBM

Rohit Suthar answered 2020-02-21T15:23:06Z
16 votes
<?php 
    list($width, $height) = getimagesize("http://site.com/image.png"); 
    $arr = array('h' => $height, 'w' => $width );
?>
Dutchie432 answered 2020-02-21T15:23:22Z
translate from https://stackoverflow.com:/questions/3890578/get-image-dimensions