[英]generate image (e.g. jpg) of a web page?
I want to create an image what a web page looks like, eg create a small thumbnail of the html + images. 我想创建一个网页看起来像的图像,例如创建一个html +图像的小缩略图。 it does not have to be perfect (eg flash /javascript rendering). 它不一定是完美的(例如flash / javascript渲染)。
I will call use the code on linux, ideally would be some java library, but a command line tool would be cool as well. 我将调用linux上的代码,理想情况下是一些java库,但命令行工具也会很酷。
any ideas? 有任何想法吗?
you can get it nearly perfect, and cross platform too, by using a browser plugin. 通过使用浏览器插件,您可以使其近乎完美,并且也可以跨平台。
FireShot or ScreenGrab for Firefox. 适用于Firefox的FireShot或ScreenGrab 。
6 Google Chrome Screenshot Webpage Capture Extensions 6 Google Chrome屏幕截图网页捕获扩展程序
BrowserShots is an open source project that may have some code you can use. BrowserShots是一个开源项目,可能有一些你可以使用的代码。
also see: 另见:
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: 要使用ImageMagick在终端中截取屏幕截图,请在终端中键入以下行,然后在屏幕的某个部分单击并拖动鼠标:
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. 您可以使用xwininfo和import的混合来检索浏览器的窗口ID并制作该窗口的屏幕截图。 A bash script to automate this process would be something like this: 用于自动执行此过程的bash脚本将是这样的:
#!/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 该脚本将在当前目录下以tumb.png的名称创建一个100x100的Firefox屏幕截图
Several sources show how to run a bash script from inside a Java application, google can help you on that. 几个来源展示了如何从Java应用程序内部运行bash脚本,谷歌可以帮助你。 If you are in a hurry, check this and this . 如果你赶时间,请检查这个和这个 。
If you're interested in Java, maybe you could look at browser automation using Selenium-RC http://seleniumhq.com 如果您对Java感兴趣,也许您可以使用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. 这是一个可以安装在盒子上的小型Java服务器,程序本身将在Web浏览器中执行远程命令。
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) 像这样的步骤(顺便说一下,这是伪代码,我在php中编写了我的Selenium代码,我无法回想起100%的细节)
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 实际上,我刚刚对最后一个的确切语法做了一个快速的网络搜索...这个人有一个博客,其中可能实际上是java中的代码:) https://dev.youdevise.com/YDBlog/index。 PHP?标题= capture_screenshots_of_selenium_browser_&更= 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/ 啊......另一个网络搜索,它是你的:) http://browsershots.org/
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: 阅读本页后,我想,让我开启midori浏览器: http : //midori-browser.org/当我尝试-h选项时,我看到:
-s, --snapshot Take a snapshot of the specified URI
QutyCapt is difficult to compile, and has many dependencies. QutyCapt很难编译,并且有许多依赖项。 Midori has it less. Midori减少了。 It outputs the PNG of the website into TMP folder. 它将网站的PNG输出到TMP文件夹。 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. 之后,可以使用ImageMagick的转换程序将文件转换为缩略图大小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.