获取图像高度和宽度作为整数值?
尝试这样的:
list($width, $height) = getimagesize('path_to_image');
确保:
- 您指定正确的图像路径有
- 图像具有读取权限
- CHMOD图像DIR 755
也尝试前缀路径与$_SERVER[DOCUMENT_ROOT]
,这有时帮助,当你不能够读取文件
list($width, $height) = getimagesize($filename)
或者,
$data = getimagesize($filename);
$width = $data[0];
$height = $data[1];
更多信息:http://php.net/manual/en/function.getimagesize.php – davethegr8 2010-02-01 18:42:04
和getimagesize()返回包含图像属性的数组。
list($width, $height) = getimagesize("path/to/image.jpg");
只得到宽度和高度或
list($width, $height, $type, $attr)
得到一些更多的信息。
感谢您指出我们必须拥有PATH的事实。:) – MEM 2014-07-04 15:31:55
PHP的getimagesize()
返回一组数据。数组中的前两项是您感兴趣的两个项目:宽度和高度。要得到这些,你会简单地要求前两个指标返回数组中:
var $imagedata = getimagesize("someimage.jpg");
print "Image width is: " . $imagedata[0];
print "Image height is: " . $imagedata[1];
欲了解更多信息,请参阅the documentation。
像这样:
imageCreateFromPNG($var);
//I don't know where from you get your image, here it's in the png case
// and then :
list($width, $height) = getimagesize($image);
echo $width;
echo $height;
不要工作:'getimagesize()期望参数1是字符串,资源给定',函数'getimagesize'需要filename – lopisan 2015-08-14 07:48:42
getimagesize('image.jpg')
功能仅如果allow_url_fopen
设置为1或在服务器里面的php.ini文件, 如果未启用它,应该上使用 ini_set('allow_url_fopen',1);
使用getimagesize()函数的文件的顶部。
777在目录上是不需要的。 – poke 2010-02-01 18:57:21
@poke:你真的100%确定吗? – Sarfraz 2010-02-18 05:04:15
是的。 777意味着对所有者,团体和所有人都有读,写和执行权。你需要阅读和执行正确的目录才能访问,但你不需要写入权限;而且你也不需要每个人都有这个权利。对于不需要在目录内创建文件的每个访问,755应该都可以。 – poke 2010-02-18 18:51:50