Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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

Replies are listed 'Best First'.
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.


      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 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?
      It would be helpful if some would let me i can convert a htmlcontent into png....ASAP
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 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 FreeBeerReekingMonk (Chaplain) on Aug 25, 2016 at 12:40 UTC
    I think you need an additional tool to interface with the Windows Win32 GDI routines:

    I would just install AutoIT3, and use their screencapture capabilities

    And here is a guy that made a image resize, which you use after saving it to a temporal file.

    I could not find additional libs in perl that had screen capture abilities.

    In Linux, there are build in things, like xwd or ImageMagick to automate screenshots.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://610538]
Approved by kyle
[Corion]: So Hyperboria is an envrypted, decentralized IPv6 mesh network. I'm interested and want to look how good coverage is in my area. But the API for querying Hyperboria is only reachable over Hyperboria itself. Thanks but no thanks.

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2017-06-23 07:21 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (536 votes). Check out past polls.