简体   繁体   English

生成网页的图像(例如jpg)?

[英]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? 有任何想法吗?

Try CutyCapt , a command-line utility. 尝试CutyCapt ,一个命令行实用程序。 It uses Webkit for rendering and outputs in various formats (SVG, PNG, etc.). 它使用Webkit进行各种格式的渲染和输出(SVG,PNG等)。

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. 您可以使用xwininfoimport的混合来检索浏览器的窗口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.

相关问题 Linux中的批量适合图像(例如GIMP) - Batch fit image in Linux (e.g. GIMP) 强制 JVM 在没有页面缓存的情况下执行所有 IO(例如 O_DIRECT) - Force JVM to do all IO without page cache (e.g. O_DIRECT) 在Linux OS中更新时自动刷新打开的图形(例如在Image Magick上显示) - Autorefresh opened figure when updated in Linux OS (e.g. displayed on Image Magick) 在查看手册页时,如何查看其加载目录? (例如,本地份额与系统份额的确定)? - While viewing a man page, how can I see the directory it was loaded from? (e.g., for local share vs system share determination)? 模块化OpenJDK11 Java映像在Linux上找不到动态库(例如libjava.so) - Modular OpenJDK11 Java image can't find dynamic libraries (e.g. libjava.so) on Linux 如何在 Linux 上获得总体 RAM 使用率(例如 57%) - How to get overall RAM usage (e.g. 57%) on Linux 如何计算好CPU百分比,例如在顶部? - How is nice cpu percentage calculated, e.g. in top? 从git导入代码到Linux ide,例如kdevelop - Import code from git to Linux ide e.g. kdevelop Bash:检查是否给出了参数(例如,是否有参数“-a”?) - Bash: Check if argument is given (e.g. is there the argument "-a" ?) 如何为ARM交叉编译python包(例如Numpy) - how to cross compile python packages (e.g. Numpy) for ARM
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM