【问题标题】:Is that possible to find width and height of an image using PHP DOM?是否可以使用 PHP DOM 找到图像的宽度和高度?
【发布时间】:2012-07-21 08:54:43
【问题描述】:

我使用 curl 废弃了网页内容。并使用该 html 内容创建 DOM。我需要检查该 html 中包含的图像的大小。

是否可以使用 Php DOM 的宽度和高度(图像标签不包含宽度和高度属性)?

【问题讨论】:

标签: php html image dom


【解决方案1】:

正如您所说,img 标签不包含高度和宽度。你可以看看getimagesize PHP 函数。您需要将从报废中获得的图像 url 传递给 getimagesize 函数。

例如:

<?php 

   $size = getimagesize("http://static.php.net/www.php.net/images/php.gif");          

   print_r($size);
?>

输出是数组

Array
(
[0] => 120
[1] => 67
[2] => 1
[3] => width="120" height="67"
[bits] => 7
[channels] => 3
[mime] => image/gif
)

希望对您有所帮助。

【讨论】:

  • 这是我认为的唯一方法,而且效果很好。谢谢朋友
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-01
  • 1970-01-01
  • 2017-10-28
  • 2012-12-25
相关资源
最近更新 更多