获取图像尺寸

时间:2010-10-08 12:44:52

标签: php image dimensions

我有一个图片网址,例如$var = http://example.com/image.png

如何将其维度添加到数组 array([h]=> 200, [w]=>100) (height=200, width=100)

3 个答案:

答案 0 :(得分:111)

您可以使用getimagesize这样的功能:

list($width, $height) = getimagesize('path to image');
echo "width: " . $width . "<br />";
echo "height: " .  $height;

答案 1 :(得分:38)

使用 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(motorola字节顺序)
9 = JPC
10 = JP2
11 = JPX
12 = JB2
13 = SWC
14 = IFF
15 = WBMP
16 = XBM

答案 2 :(得分:16)

<?php 
    list($width, $height) = getimagesize("http://site.com/image.png"); 
    $arr = array('h' => $height, 'w' => $width );
?>