Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Best way to parse/evaluate HTML page contents for apparent image size

by sundialsvc4 (Abbot)
on Dec 14, 2012 at 04:22 UTC ( #1008766=note: print w/replies, xml ) Need Help??

in reply to Best way to parse/evaluate HTML page contents for apparent image size

Unfortunately, I find your question to be ... just too vague.   “The size of an image that would actually render” might be specified absolutely in the HTML, e.g. width="720px", or it might be relative, "50%", or it might not be specified at all, in which case it would depend on whatever the size of the browser window happened to be at the time.   That is to say, the actual image size is very much contextual, and in light of that, could you be a little bit more explicit as to what you need here?   (Sure, there are terrific HTML parsers available which can, with great precision, tell you precisely what the HTML says.   But that’s only part of the question.)

  • Comment on Re: Best way to parse/evaluate HTML page contents for apparent image size

Replies are listed 'Best First'.
Re^2: Best way to parse/evaluate HTML page contents for apparent image size
by Anonymous Monk on Dec 14, 2012 at 08:05 UTC
    With all due respect, the question isn't about various HTML development practices. The question is, could someone who has used perl to automate graphical web browsers (or their underlying rendering engines) recommend a library to work with the rendered image sizes in a given browser context. I'm guessing that if you have never used (for example, from doing a search on various rendering engines in CPAN) Mozilla::Mechanize, or WWW::Mechanize, or WWW::WebKit, or something else like it I'm unaware of, you'll be of limited help in making a recommendation.

      And my sincere opinion here is that if you want to determine the effective size of an image on the browser screen, there are many factors which influence this.   (And yes, I hadn’t even considered CSS.)   Sure, all these tools exist for getting to the HTML, etc., but that’s only the tip of the question being posed as I read it.   There are so many potentially influencing variables here, apart from the HTML itself, that the objective is at best difficult to answer.   I found the question as-stated to be vague, as in, difficult to ascertain what potential factors were intended to be in-bounds or not.   Getting to the HTML and/or CSS elements in Perl, fortunately, is a technical matter that has been very-well solved by CPAN.

        I think you misunderstand what the various mechanize tools offer. You are manipulating a browser like Firefox that will offer you access to it's DOM and rendered image sizes... after it has been rendered, after all the CSS rules have been applied, and various directives like "px" or "%" values of the images have been applied.
        Yes, it looks like $mech->element_coordinates( $element ) will do precisely what I need. A series of arithmetic operations should quickly give me actual rendered image size, thank you.

        In absence of someone saying 'ah, but this module is better' or 'that module is pure perl', I'm planning on going this route.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1008766]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2017-06-27 02:51 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (598 votes). Check out past polls.