Convert Webpage To Image

Home » CentOS » Convert Webpage To Image
CentOS 18 Comments

What is the easiest way to convert a webpage into a jpg or png file? I’ve seen several programs that can do various conversions, but nothing open source that can do it in a single conversion.

Just wondering if anyone on the list has suggestions for something I can put into a script to convert a webpage into a file I can use with my screensaver.

c

18 thoughts on - Convert Webpage To Image

  • Perhaps use one of the PDF printing tools (where you can print to a PDF
    file) and then use convert from ImageMagick to convert the PDF file to a graphics format.?

  • I don’t really think this is on topic, but regardless, have a look at phantomjs’ [1] rendering capabilities [2].

    Ciao

  • I’m assuming he’s using CentOS and wants a solution to a task he wants to do with it. So possibly tenuously on-topic…

  • Do you want do this automagically? If not you could use ksnapshot, then use gimp to remove the surrounding browser junk.

  • If you just need what is on your screen, you could use ImageMagick’s import command. You select what you need with the mouse, and save it as an image format, for example

    import myshot.jpg

  • I wrote a few lines to do this, but it involves using firefox, and ‘import’ from ImageMagick.

    The first script starts firefox in a virtual frame:

    ===
    Xvfb :2 -screen 0 1280x1024x24 > /dev/null 2>&1 &
    export DISPLAY=localhost:2.0

    firefox http://ip.of.your.page/page.html &
    ===

    Then the second script captures/crops what I want:

    ===
    export DISPLAY=localhost:2.0
    import -crop ‘1024×512+54+235’ -window root /path/to/result.png
    ==

    You’ll have to adjust the crop values to what you want.

  • But what if the size of the website is larger than the screen size? I
    assume the OP wants to “see” the whole website in a single picture, and the website might span more than a single visible screen (and require scrolling to see the whole thing).

    All screenshot-related methods would then need to take multiple pictures, scroll the website in the browser a “windowfull” at a time in all directions, and afterwards calculate how to concatenate all those pictures into a big one. While this can be done in principle, I think that any implementation would get Real Ugly Real Soon(tm).

    A more reasonable approach would be to have the browser itself dump the image of the site — the browser is the one actually rendering the thing from html in the first place. Any browser plugins around for this?

    Best, :-)
    Marko

  • This will do exactly what you want without resorting to hackery or using external services. It has a component to convert to both pdf or an image and uses webkit.
    http://code.google.com/p/wkhtmltopdf/

    The binaries are standalone and require no special dependencies. The command line is sensitive to the order you place options, but otherwise it works very well.

    ❧ Brian Mathis

  • Among those interactive, the Screengrab Firefox extension does it. Among those non-interactive, phantomjs should do it.

    Mihai

LEAVE A COMMENT