generate image (e.g. jpg) of a web page?

后端 未结 5 1314
深忆病人
深忆病人 2021-02-07 07:00

I want to create an image what a web page looks like, e.g. create a small thumbnail of the html + images. it does not have to be perfect (e.g. flash /javascript rendering).

相关标签:
5条回答
  • 2021-02-07 07:37

    If you're interested in Java, maybe you could look at browser automation using Selenium-RC http://seleniumhq.com

    It's a little java server that you can install on the box and the program itself will execute remote commands in a web browser.

    Steps like (this is pseudo code by the way, I code my Selenium in php and I can't recall 100% of the specifics off the top of my head)

    selenium.location("http://foo.com")
    selenium.open("/folder/sub/bar.html")
    selenium.captureScreenshot("/tmp/" + this.getClass().getName() + "."
                                   + testMethodName + ".png");
    

    Actually, I just did a quick websearch for the exact syntax on that last one ... and this guy has a blog with what might actually be working code in java :) https://dev.youdevise.com/YDBlog/index.php?title=capture_screenshots_of_selenium_browser_&more=1&c=1&tb=1&pb=1

    There's also a number of websites that provide this service "cross browser and OS" I just can't recall what they are. Basically they've got a cloud of every single operating system and browser combination, and they log on with each machine, take a screen and store it on their site for you to come back to in a few hours when they're done.

    Ahh... another websearch and it's yours :) http://browsershots.org/

    0 讨论(0)
  • 2021-02-07 07:46

    After reading this page, I was thinking, let me fire up midori browser: http://midori-browser.org/ and when I tried the -h option, I have seen:

      -s, --snapshot      Take a snapshot of the specified URI
    

    QutyCapt is difficult to compile, and has many dependencies. Midori has it less. It outputs the PNG of the website into TMP folder. One can get the file with:

    midori -s http://www.rcdwealth.com new.png 2>/dev/null | awk '{ print $4}'
    

    After that, the file can be converted to thumbnail size by using ImageMagick's convert program.

    0 讨论(0)
  • 2021-02-07 07:50

    Try CutyCapt, a command-line utility. It uses Webkit for rendering and outputs in various formats (SVG, PNG, etc.).

    0 讨论(0)
  • 2021-02-07 07:51

    To take a screenshot in the terminal with ImageMagick, type the following line into a terminal and then click-and-drag the mouse over a section of the screen:

    import MyScreenshot.png
    

    To capture the entire screen and after some delay and resize it, use the following command:

    import -window root -resize 400×300 -delay 200 screenshot.png 
    

    You may use a mixture of xwininfo and import to retrieve the window id of the browser and make a screenshot of that window. A bash script to automate this process would be something like this:

    #!/bin/bash
    window_id=`xwininfo -tree -root | grep Mozilla | awk '{print $1}'`
    import -window $window_id -resize 100x100 tumb.png
    

    This script will create a 100x100 screenshot of Firefox on the current directory under the name tumb.png

    Several sources show how to run a bash script from inside a Java application, google can help you on that. If you are in a hurry, check this and this.

    0 讨论(0)
  • 2021-02-07 07:56

    you can get it nearly perfect, and cross platform too, by using a browser plugin.

    • FireShot or ScreenGrab for Firefox.

    • 6 Google Chrome Screenshot Webpage Capture Extensions

    BrowserShots is an open source project that may have some code you can use.

    also see:

    • Command line program to create website screenshots (on Linux)
    • Convert web page to image
    • How to take screenshot of whole web page, rather than what shows on the screen
    • What is the best way to create a web page thumbnail?
    • Convert HTML to an image
    0 讨论(0)
提交回复
热议问题