1. 安装cutycapt依赖包:
yum -y install lrzsz vim patch make gcc gcc-c++ libtool openssl openssl-devel libxml2* libxslt* popt popt-devel libXpm libXpm-devel curl-devel openldap openldap-devel m4 autoconf ncurses-devel libXi-devel libXinerama-devel libmng* libGLU-devel libICE-devel libSM-devel libXcursor-devel libXext-devel libXfixes-devel libXft-devel libXrandr-devel libXrender-devel libXt-devel libpng-devel libqt4-webkit libqt4-dev g++ -y
yum install svn 注: 如果系统环境已经安装svn则不用yum安装 否则使用svn时会报错, 如果没有svn 可以直接装上
2. 下载相关软件包
cd /usr/local/webserver
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
3.安装:
cd /usr/local/webserver
rpm -ivh qt44-4.4.3-10*
rpm -ivh qt44-x11-4.4.3-10_4.el5.x86_64.rpm
rpm -e qt-devel --nodeps --allmatches
rpm -ivh qt44-devel-4.4.3-10*
4. 修改环境变量
export QTDIR=/usr/lib64/qt44
export QTLIB=/usr/lib64/qt44/lib
export QTINC=/usr/lib64/qt44/include
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH 注意这个位置 不要替换以前的 只是添加
export PATH=$QTDIR/bin:$PATH:$HOME/bin 同上
5. 下载cutycapt
svn co svn://svn.code.sf.net/p/cutycapt/code/ cutycapt
mv cutycapt/CutyCapt /usr/local/webserver/CutyCapt
rm -rf cutycapt
cd /usr/local/webserver/CutyCapt
qmake
make
6. 安装模拟 x-server 服务端
cd /usr/local/webserver
wget http://www.flexthinker.com/wp-content/uploads/2009/11/xvfb-run.sh.txt
mv ./xvfb-run.sh.txt /usr/local/webserver/CutyCapt/xvfb-run.sh
chmod +x /usr/local/webserver/CutyCapt/xvfb-run.sh
6. 添加中文字体
将windows 下的 C:\WINDOWS\Fonts 中的simsun.ttc 复制到linux上 具体过程如下
1. mkdir -p /usr/share/fonts/chinese/windows
2. chmod -R 755 /usr/share/fonts/chinese/windows
3. 将windows下的 simsun.ttc 添加到 /usr/share/fonts/chinese/windows 下 (rz命令)
4. cd /usr/share/fonts/chinese/windows
5. ttmkfdir -e /usr/share/X11/fonts/encodings/encodings.dir
6. vim /etc/fonts/fonts.conf 添加一行 /usr/share/fonts/chinese/windows
24 <!-- Font directory list -->
25
26 <dir>/usr/share/fonts</dir>
27 <dir>/usr/share/X11/fonts/Type1</dir> <dir>/usr/share/X11/fonts/OTF</dir>
28 <dir>/usr/share/fonts/chinese/windows</dir> 添加此行,注意<dir>标签
29 <dir>~/.fonts</dir>
30
7. /etc/init.d/xfs restart
8.fc-list :lang=zh-cn 查看字体有没有添加成功
NSimSun,新宋体:style=Regular
SimSun,宋体:style=Regular
7. 执行截图命令:
/usr/local/webserver/CutyCapt/xvfb-run.sh --server-args="-screen 0, 1024x768x24" /usr/local/webserver/CutyCapt/CutyCapt --url=http://www.baidu.com --out=baidu.jpg
参考网址:
http://blog.sina.com.cn/s/blog_a5952cca010165cj.html
http://blog.chinaunix.net/uid-21374062-id-2983850.html
http://cutycapt.sourceforge.net/
http://blog.csdn.net/kindy1022/article/details/7623940
如果安装报错 可参考下面文档:
1. 安装 qt qtwebkit
默认yum的是qt3及qt4.2 不带qtwebkit的,想用qtwebkit要装更高的版本,就需要重新更改yum配置
导入 ATrpms’ signing key(导入Key),执行
# rpm --import http://packages.atrpms.net/RPM-GPG-KEY.atrpms
旧版本rpm不能导入
可以用
# wget http://packages.atrpms.net/RPM-GPG-KEY.atrpms
# rpm --import RPM-GPG-KEY.atrpms
备份原来的源
# cp /etc/yum.conf /etc/yum.conf.bak
修改yum.conf
# vi /etc/yum.conf
如果要装qtwebkit要装更高的版本 的在下面加上
#########################################
[atrpms]
name=Fedora Core $releasever - $basearch - ATrpms
baseurl=http://dl.atrpms.net/el$releasever-$basearch/atrpms/stable
gpgkey=http://ATrpms.net/RPM-GPG-KEY.atrpms
gpgcheck=1
=====================================================================================
如果要装qt-47 的,改成以下, 进行网页截图的话 就改成一下这样
##########################################
[atrpms]
name=Fedora Core $releasever - $basearch - ATrpms
baseurl=http://dl.atrpms.net/el$releasever-$basearch/atrpms/testing
gpgkey=http://ATrpms.net/RPM-GPG-KEY.atrpms
gpgcheck=1
# :wq保存退出
# yum list | grep qt47
可以发现atrpms里面有qt47了
安装
# yum install qt47 qt47-webkit qt47-webkit-devel qt47-x11 qt47-sqlite
安装gcc-c++
# yum install gcc-c++
环境变量配置
修改 /etc/profile
# vi /etc/profile
加入
export QTDIR=/usr/lib64/qt47
##export QTLIB=/usr/lib64/qt47/lib 在真实实验中,没有发现/lib 和 /include包,所以也就不需要配置了
##export QTINC=/usr/lib64/qt47/include
##export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
export PATH=$QTDIR/bin:$PATH
保存退出后,运行一次该文件
#source /etc/profile
输入qmake有显示成功配置qt
2. 安装 cutycapt
# svn co https://cutycapt.svn.sourceforge.net/svnroot/cutycapt
# mv cutycapt/CutyCapt /usr/local/CutyCapt
# cd /usr/local/CutyCapt
# qmake
# make
出现以下错误
/usr/lib64/qt47/libQtWebKit.so: undefined reference to `sqlite3_prepare16_v2‘
/usr/lib64/qt47/libQtWebKit.so: undefined reference to `sqlite3_column_value‘
collect2: ld returned 1 exit status
make: *** [CutyCapt] Error 1
解决:
#yum update sqlite
再次执行
# make
以下表示make成功
[root@localhost CutyCapt]# make
g++ -Wl,-O1 -o CutyCapt CutyCapt.o moc_CutyCapt.o -L/usr/lib64/qt47 -lQtWebKit -lQtSvg -L/usr/lib64/qt47 -lQtGui -lQtNetwork -lQtCore -lpthread
如出现
/usr/local/CutyCapt/CutyCapt: /usr/local/lib/libpng12.so.0: no version information available (required by /usr/lib64/qt47/libQtGui.so.4)
解决方法
cd /usr/local/lib
sudo mv libpng12.so.0 libpng12.so.0.backup
sudo ln -sf /usr/lib/libpng12.so.0 libpng12.so.0
这样就OK了.
3. 安装模拟 x-server 服务端
wget http://www.flexthinker.com/wp-content/uploads/2009/11/xvfb-run.sh.txt
mv ./xvfb-run.sh.txt /usr/local/CutyCapt/xvfb-run.sh
chmod u+x /usr/local/CutyCapt/xvfb-run.sh
4. 开始欢快的截图吧
/usr/local/CutyCapt/xvfb-run.sh --server-args="-screen 0, 1024x768x24" /usr/local/CutyCapt/CutyCapt --url=http://www.163.com --out=163.jpg
或执行
xvfb-run --server-args="-screen 0, 1024x768x24" ./CutyCapt --url=http://www.baidu.com/ --out=localfile1.png --body-string=utf-8
出现-bash: xvfb-run: command not found 或 xauth : command not found
安装
# yum install Xorg Xvfb xauth xorg-x11-fonts*
等一会见到生成了localfile1.png表示成功了
5. 如果看不到汉字或乱码,需要安装chinese字体
# yum install fonts-chinese
6. 由于截屏的是整个网站的页面,只需要第一屏幕
convert -crop 1024x768+0+0 163.jpg 1632.jpg
7 . 缩小图片
convert -resize 40%x40% 1632.jpg 1632.jpg
参考URL:
http://leyewen.blog.163.com/blog/static/25060614201212324052743/
http://blog.163.com/bqj123@126/blog/static/28351334201091955030355/
http://www.2cto.com/os/201203/122079.html
http://www.2cto.com/os/201203/122079.html
原文地址:http://2385662.blog.51cto.com/2375662/1706253