开发者

Modify inline image inline style with PHP Simple HTML DOM Parse

开发者 https://www.devze.com 2023-01-30 02:02 出处:网络
I have an image with source that looks like <img alt=\"\" src=\"./userfiles/images/Water%20lilies(1).jpg\" style=\"width:800px;height:600px;\" />

I have an image with source that looks like

<img alt="" src="./userfiles/images/Water%20lilies(1).jpg" style="width:800px;height:600px;" />

I'd like to find out if the width is greater than 750px if yes the need to change the style="width开发者_如何学Go: xxx" to be style="width: 750px;"

Is this possible with the Simple DOM?

All i can do now it to set the width of the image which doesnt seem to work because the style overwrites it

foreach($content->find('img') as $element) { $element->width = '750'; }


You can get the image info using: http://php.net/manual/en/function.getimagesize.php

IF you are pulling raw HTML (which I cant tell how you are getting DOM elements in your PHP) you can wget the image, store it tmp, and then get the image info.

In other words, if you need image info via PHP, you need to have it stored and readable

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号