Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Howto Save/Convert HTML into JPEG/PNG with Perl

by neversaint (Deacon)
on Apr 17, 2007 at 14:41 UTC ( #610538=perlquestion: print w/ replies, xml ) Need Help??
neversaint has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way to do it with Perl? Any CPAN module that does that?
I want to convert many of such html files verbatim, into figures (JPEG/PNG) format.

---
neversaint and everlastingly indebted.......

Comment on Howto Save/Convert HTML into JPEG/PNG with Perl
Re: Howto Save/Convert HTML into JPEG/PNG with Perl
by jettero (Monsignor) on Apr 17, 2007 at 15:01 UTC

    Personally, I'm not aware of any way to do this short of loading up the html in a browser and issuing a screencap of the browser window. The main reason is that it takes 30 megs of compiled bloat for firefox to render an html file and the conversion is browser dependent.

    -Paul

      There even is a module for doing just that, Win32::CaptureIE - it takes screenshots from a page as viewed by Internet Explorer and stitches them together.

        Win32:CaptureIE DOES NOT WORK!!!!!!
Re: Howto Save/Convert HTML into JPEG/PNG with Perl
by moklevat (Priest) on Apr 17, 2007 at 15:07 UTC
    It sounds like you would like a module that will read the HTML file, render it, and then write out a png or jpeg image of the rendered page. Perhaps someone else knows of such a beast, but my cursory look through CPAN did not turn this up.

    Since the structure of the figure is relatively simple, a bunch of tables each containing rectangle-on-a-line with varying offsets, you may be better off parsing the HTML file to extract the sequence information and offset data (the first "td width=" in each table) and rendering rectangle-on-a-lines in PNG using GD::Simple. This would give you more control over the appearance of the image

    Update:Ooh, Look at that! Corion found a module that would work after all.

Re: Howto Save/Convert HTML into JPEG/PNG with Perl
by dragonchild (Archbishop) on Apr 17, 2007 at 15:15 UTC
    If you're in OSX, you can use Automator to take screenshots. If you're in Linux, I'm pretty sure that there are similar scripting utilities. Perl isn't always the best solution.

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Re: Howto Save/Convert HTML into JPEG/PNG with Perl
by isync (Hermit) on Apr 17, 2007 at 20:56 UTC
    So 1 more who'd like to enter the multi-million dollar business of thumbnail generation! ;-)

    In fact I found 3 solutions.

    1. You can use html2ps -> then convert the .ps with imagemagick to a .png (works, but all thumbs have a white background - as html2ps is intended for printing)

    2. The medium-weight approach of using a browser's render engine and get the output (I used the kwebdesktop library on linux and got mediocre results so far, render errors and no flash, and I think it wastes a LOT of memory! and I can't control the user-agent string easily)

    3. The heavy-weight approach of using an external browser and take a capture of the browser's window. Which I didn't try so far as I dislike the idea of the overall design.


    Remark 1: To my knowledge there is no all-in-one html-render-and-output-as-image module on cpan.

    Remark 2: Which module on Corion?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://610538]
Approved by kyle
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (11)
As of 2014-11-27 08:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (182 votes), past polls