Skip to content

Instantly share code, notes, and snippets.

@errord
Created August 18, 2014 05:49
Show Gist options
  • Save errord/f766cbf401e760e7ea44 to your computer and use it in GitHub Desktop.
Save errord/f766cbf401e760e7ea44 to your computer and use it in GitHub Desktop.
linxu下使用xvfb虚拟设备进行截图
这2种方法经测试都已经通过。
服务器版本是:ceontos5.4 64位系统。
一、Xvfb + html2image
yum install Xvfb
yum install xorg-x11-fonts*
wget http://www.ys250.com/src/html2image.x86_64.tar.gz
#wget http://www.ys250.com/src/html2image.i386.tar.gz
mv html2image /usr/local/
cd /usr/local/html2image
export LD_LIBRARY_PATH=./
mkdir -p /usr/X11R6/lib
ln -s /usr/share/X11 /usr/X11R6/lib/X11
#通过运行Xvfb来模拟 x-server 端
Xvfb :1-screen 0 1024x768x24 -nolisten tcp -audit 4-auth X1.cfg& export DISPLAY=:1 firefox
#生成google.com 的预览图片
/usr/local/html2image/html2image www.google.com gg.jpg
二、Xvfb + CutyCapt
yum install libXi-devel
yum install libXinerama-devel
wget http://dl.atrpms.net/el5-x86_64/atrpms/testing/qt44-4.4.3-10_4.el5.x86_64.rpm
wget http://dl.atrpms.net/el5-x86_64/atrpms/testing/qt44-x11-4.4.3-10_4.el5.x86_64.rpm
wget http://dl.atrpms.net/el5-x86_64/atrpms/testing/qt44-devel-4.4.3-10_4.el5.x86_64.rpm
rpm -ivh qt44-4.4.3-10_4.el5.x86_64.rpm
rpm -ivh qt44-x11-4.4.3-10_4.el5.x86_64.rpm
rpm -ivh qt44-devel-4.4.3-10_4.el5.x86_64.rpm
# qt44-devel 安装不上执行下面这句删掉lao的devel包
rpm -e qt-devel --nodeps --allmatches
vi /etc/profile
export QTDIR=/usr/lib64/qt44
export QTLIB=/usr/lib64/qt44/lib64
export QTINC=/usr/lib64/qt44/include
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
export PATH=$QTDIR/bin:$PATH
source /etc/profile
svn co https://cutycapt.svn.sourceforge.net/svnroot/cutycapt
mv cutycapt/CutyCapt /usr/local/CutyCapt
cd /usr/local/CutyCapt
qmake
make
#使用xvfb-run脚本来管理Xvfb
wget http://www.ys250.com/src/xvfb-run.sh
mv xvfb-run.sh/usr/local/CutyCapt/xvfb-run.sh
截图
/usr/local/CutyCapt/xvfb-run.sh--server-args="-screen 0, 1024x768x24"/usr/local/CutyCapt/CutyCapt --url=http://www.5w.com --out=5w.jpg
#缺陷就是flash没解析出来
安装中文字体,可以从windows拷一些ttf文字到 /usr/share/fonts/truetype/目录
yum install fonts-chinese yum安装一个中文字体也行。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment