php 获取图像尺寸
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3890578/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get image dimensions
提问by James
I have an url to the image, like $var = http://example.com/image.png
我有一个图片的网址,比如 $var = http://example.com/image.png
How do I get its dimensions to an array, likearray([h]=> 200, [w]=>100)
(height=200, width=100)
?
我如何将它的维度设置为一个数组,比如array([h]=> 200, [w]=>100)
(height=200, width=100)
?
回答by Sarfraz
You can use the getimagesize
function like this:
您可以getimagesize
像这样使用该函数:
list($width, $height) = getimagesize('path to image');
echo "width: " . $width . "<br />";
echo "height: " . $height;
回答by Rohit Suthar
Using getimagesizefunction, we can also get these properties of that specific image-
使用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);
?>
Result like this -
结果是这样的——
Width: 200
Height: 100
Type: 2
Attribute: width='200' height='100'
宽度:200
高度:100
类型:2
属性:width='200' height='100'
Type of image consider like -
图像类型考虑如下 -
1 = GIF
2 = JPG
3 = PNG
4 = SWF
5 = PSD
6 = BMP
7 = TIFF(intel byte order)
8 = TIFF(motorola byte order)
9 = JPC
10 = JP2
11 = JPX
12 = JB2
13 = SWC
14 = IFF
15 = WBMP
16 = XBM
1 = GIF
2 = JPG
3 = PNG
4 = SWF
5 = PSD
6 = BMP
7 = TIFF(英特尔字节顺序)
8 = TIFF(摩托罗拉字节顺序)
9 = JPC
10 = JP2
11 = JPX
12 = JB2
13 = SWC
14 = IFF
15 = WBMP
16 = XBM
回答by Dutchie432
<?php
list($width, $height) = getimagesize("http://site.com/image.png");
$arr = array('h' => $height, 'w' => $width );
?>