可以使用PHP DOM查找图像的宽度和高度吗? [英] Is that possible to find width and height of an image using PHP DOM?

查看:87
本文介绍了可以使用PHP DOM查找图像的宽度和高度吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I scrap a webpage content using curl. And create DOM using that html content. I need to check size of the images that contained in that html.

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

Is that possible to width and height of an using Php DOM (image tag not containing the width and height attribute)?

推荐答案

正如你所说img tag不包含height&宽度。您可以查看 getimagesize PHP函数。你需要传递你从废弃到getimagesize功能的图像网址。

As you are saying img tag is not containing height & width. You can look at getimagesize PHP function. You need to pass image url you getting from scrapping to getimagesize function.

Ex:

<?php 

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

   print_r($size);
?>

OUTPUT 是数组

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

希望这有帮助。

这篇关于可以使用PHP DOM查找图像的宽度和高度吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆