php 获取图像尺寸[重复]

oxf4rvwz  于 2023-05-12  发布在  PHP
关注(0)|答案(3)|浏览(88)

此问题已在此处有答案

How can I find the width of an image using PHP?(7个回答)
9年前关闭。
我有一个图像的URL,如$var = http://example.com/image.png

如何获取数组的维数比如array([h]=> 200, [w]=>100)(height=200, width=100)

kkbh8khc

kkbh8khc1#

你可以像这样使用getimagesize函数:

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

vsdwdz232#

使用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);
?>

结果如下-

宽度: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 = JB2
13 = SWC
14 = IFF
15 = WBMP
16 = XBM

z6psavjg

z6psavjg3#

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

相关问题