Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2228918
  • 博文数量: 533
  • 博客积分: 8689
  • 博客等级: 中将
  • 技术积分: 7046
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-26 10:00
文章分类

全部博文(533)

文章存档

2024年(2)

2023年(4)

2022年(16)

2014年(90)

2013年(76)

2012年(125)

2011年(184)

2010年(37)

分类: LINUX

2012-05-29 15:19:46














How to Capture a Website Screenshot in Linux

You might be wondering how to capture a website screenshot (as thumbnail) but you dont know how to do it. Although PHP GD library is available, it is just not possible to do the task with php. You will need a linux server running xwindow system and a browser like KDE konquerer or firefox. In this tutorial i am going to show you how to capture a website screenshot with  in a Centos/RHEL server. I am documenting here the experiment i conducted in my VPS so that my work could be helpful.

What is Needed?

Linux Server with Centos/RHEL 
Khtml2Png ()
ImageMagick (http://imagemagick.org)
KDE Desktop Environment
Cmake - 

Screenshot Capturing Basics

Most linux servers will usually not have a graphics card or output device like monitor. This is usually called headless server and the alternate way is using a Xvfb or Vncserver (Xserver with virtual frame buffer). It is basically a virtual display that doesnt need a graphics device and monitor. Anything written to Xvfb, can be captured as screenshot. In this tutorial, I will be using Xvfb without making use of khtml2png and it is the most simple method of doing it.

First install Xvfb server and ImageMagick

yum install Xvfb ImageMagick

then,

yum install firefox

start the virtual display

> Xvfb :2 -screen 0 1024x768x24&
// This starts the virtual server with display no 2, screen no 1 on resolution 1024x768 with color depth of 24 bit.

Run the firefox on the virtual display in the command line

> DISPLAY=:2 firefox

Wait for 5 seconds until, it loads and then capture a screenshot with ImageMagick's import tool

> import -window root example.png

once this is done, you can resize the images later with convert tool

Using Khtml2PNG

khtml2png is another way of capturing a website screenshot of specified width and height from Xvfb virtual server. More information can be found at.

khtml2png requires KDE, gcc compiler, cmake and kde-devel libraries,

If you have a new linux server, prepare your server with c compiler and other utilities

Install Basic Tools

yum install gcc gcc-c++ automake autoconf nano zlib zlib-devel

Install KDE desktop environment

yum groupinstall "X Window System" "KDE (K Desktop Environment)"

Install KDE developer libraries

yum install kdelibs kdelibs-devel

Install Xvfb Virtual Frame Buffer

yum install Xvfb xorg xorg-x11-font*

Install Cmake

Cmake is cross plaform make utility. You cannot install using yum so you have to download the source files and compile it.

wget
tar zxf cmake-2.7.1.tar.gz
cd cmake-2.7.1

then

./bootstrap
make 
make install

Install Khtml2PNG

Download the source files from .

wget
tar xzf khtml2png-2.7.5

./configure
make install

Final Steps

Start Xvfb virtual server, then launch the khtml2png to grab a website screenshot

> Xvfb :2 -screen 0 1024x768x24&
> export DISPLAY=localhost:2.0

then run khtml2png2

> khtml2png2 --sw 200 --sh 150 example.png

--sh and --sw indicates both scaled width and height

To view the image in the browser copy those created screenshot to apache /var/www/html and point your browser to 

If you want khtml2png run as daemon you might want to install  available from sourceforge.

Useful Links

 - Web page screen shot grabber using Mozilla.
 - A screenshot grabber written in Perl.
 - A daemon for khtml2png

Common Errors

I am documenting the common errors i got and how i fixed those. Few i was able to fix while others i couldnt fix.

khtml2png2: cannot connect to X server

[This means you have not assigned the display where Xvfb is running. Try export DISPLAY=localhost:2.0 in the commandline

Couldn't open RGB_DB '/usr/share/X11/rgb'

[Xvfb might throw this error if you set the resolution to 32 bit color depth. Lower the resolution to 24 or 16bit color.
Example: Xvfb :2 -screen 0 800x600x24&]

error opening security policy file /usr/lib/xserver/SecurityPolicy

[Login as a user other than root]

Could not init font path element /usr/share/X11/fonts/TTF/, removing from list!
Could not init font path element /usr/share/X11/fonts/OTF, removing from list!
Could not init font path element /usr/share/X11/fonts/Type1/, removing from list!
Could not init font path element /usr/share/X11/fonts/CID/, removing from list!
Could not init font path element /usr/share/X11/fonts/100dpi/, removing from list!
Could not init font path element /usr/share/X11/fonts/75dpi/, removing from list!

[Try yum install xorg-x11-font*]

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
QT_INCLUDE_DIR (ADVANCED)

[Install qt and qt-devel packages. If that doesnt work, try rebooting the server and this might go off! ]

You can also place  in my blog.

Back to 















使用khtml2png对网站进行整体抓图
2010-07-08 10:55
转载自 
最终编辑 

(zz: )

khtml2png is a command line program to create PNG images out of webpages. Despite the name, it can also produce JPEG images.

下载:

或者

Requirements:
g++
KDE 3.x
kdelibs for KDE 3.x (kdelibs4-dev)
zlib (zlib1g-dev)
cmake

我以centos5.2为例

Khtml2png基于KDE,要用到Konqueror浏览器

安装必须的包

yum install gcc gcc-c++ automake autoconf nano zlib zlib-devel   kdelibs kdelibs-devel
yum groupinstall “X Window System” “KDE (K Desktop Environment)”
yum install Xvfb xorg “xorg-x11-font*”
yum install qt*

安装中文语言包,否则中文字符乱码

yum install fonts-chinese fonts-ISO8859-2-75dpi

编译安装cmake

wget 
tar -zxvf cmake-2.6.2.tar.gz
cd cmake-2.6.2
./bootstrap
make
make install

安装khtml2png

wget  

修改configure 文件 指定qt库

cmake -G KDevelop3 -D QT_INCLUDE_DIR:PATH=/usr/lib/qt-3.3/include .
cmake -D QT_INCLUDE_DIR:PATH=/usr/lib/qt-3.3/include .
./configure
make
make install

启动后台虚拟图形终端

Xvfb :2 -screen 0 1024×768x24&
export DISPLAY=localhost:2.0

修改kde设置
~/.kde/share/config/kcookiejarrc

增加

[Cookie Dialog]
PreferredPolicy=2
ShowCookieDetails=false

[Cookie Policy]
CookieDomainAdvice=
CookieGlobalAdvice=Accept

~/.kde/share/config/khtmlrc
增加

[Java/JavaScript Settings]
PopupBlockerPassivePopup=false

OK
khtml2png2 –get-body -w 1024 -h 800  sysbus.png






阅读(2919) | 评论(0) | 转发(0) |
0

上一篇:find

下一篇:安装rsync的脚本

给主人留下些什么吧!~~