2009年11月19日 星期四

網頁縮圖教學

System Requirements:

Linux based OS, GTK 2, Internet connection, High color display mode.

Linux kernel - 2.2.14 or higher with the following libraries or packages:

glibc 2.3.2 or higher
XFree86-3.3.6 or higher
gtk+2.0 or higher
fontconfig (also known as xft)
libstdc++5
Tested on Red Hat Fedora 5 , Novell SuSE Linux 10.0, Red Hat Fedora 4, Red Hat Enterprise Linux 4 , Red Hat Enterprise Linux 3

If you system doesn't have libpangocairo, please try to install libpangocairo ( type "rpm -Uivh cairo-1.0.2-1.1.fc4.nr.i386.rpm glitz-0.4.3-1.1.fc4.nr.i386.rpm libpixman-0.1.5-1.1.fc4.nr.i386.rpm pango-1.10.3-1.1.fc4.nr.i386.rpm pango-devel-1.10.3-1.1.fc4.nr.i386.rpm" to install)

If you are using Fedora Linux, You can also to use the software installation tool Yum to install those dependencies.

Known Issues
Page content generated by plugins (such as Flash-based content) is not included in saved images. This problem should disappear after Mozilla bug 313462 is fixed. Instead, you can try our windows based component htmlsnapshot!


Usage:

1. Extract the install package to a folder. (for example, /html2image/)

2. Add the folder path to ld path for shared library. For example

export LD_LIBRARY_PATH=/html2image/

or

you can also add the path to html2image to /etc/ld.so.conf, then run ldconfig

3. Run html2image which is a command line tool to convert html to image. (bmp and png image format are supported currently). The following are some examples:

a. Convert url to bmp

html2image www.google.com a.bmp

b. Convert url to jpg

html2image www.google.com a.jpg

c. Convert local html file to png

html2image file://home/user/test.html a.png

4. For more help, type "html2image -h"
5. You can also run html2image with Xvfb on the text mode console. In the html2image folder, run the below command:

./Xvfb :1 -screen 0 640x480x24 -nolisten tcp -audit 4 -auth X1.cfg & export DISPLAY=:1 & ./html2image www.google.com /root/b.png

The command can be called in batch or web CGI script files to convert url or html to image files..

How to use html2image linux on CentOS 5

here is detailed example on how to use html2image linux on CentOS 5. This serves as a good example on how to use html2image. Other Linux distribution can be done similarly

1. Install CentOS.

2. Login into the server (you can use the text mode login here)

3. Enter a folder, download html2image

wget http://www.guangmingsoft.net/htmlsnapshot/html2image.i386.tar.gz

4. Extract html2image

tar xvzf html2image.i386.tar.gz
cd html2image
export LD_LIBRARY_PATH=./

5. Make a symbol link for X11

ln -s /usr/share/X11 /usr/X11R6/lib/X11

You should do this to avoid the X11 error "could not open default font 'fixed'"

6. Run Xvfb
./Xvfb :1 -screen 0 640x480x24 -nolisten tcp -audit 4 -auth X1.cfg & export DISPLAY=:1

7. Now you can run html2image, it should work
./html2image www.google.com a.jpg

How to use html2image linux on Ubuntu 64

Here is detailed example on how to use html2image linux on Ubuntu 64 bit (Ubuntu 7.10 - the Gutsy Gibbon)

This serves as a good example on how to use html2image. Other 64 bit Linux distribution can be done similarly.

1. Install Ubuntu 64

2. Login into the server (you can use the text mode login here. This is suitable for headless server as well)

If you are in GUI mode, Ctrl+Alt+F2 will switch you to text mode.

3. Enter a folder, download html2image

wget http://www.guangmingsoft.net/htmlsnapshot/html2image.i386.tar.gz

4. Extract html2image

tar xvzf html2image.i386.tar.gz
cd html2image
export LD_LIBRARY_PATH=./

4. Install 32bit application support libraries.

sudo apt-get install ia32-libs

sudo apt-get install lib32nss-mdns (Needed for Ubuntu9)

5. Install Xvfb coming with the Ubuntu

sudo apt-get install xvfb

6. Run Xvfb

Xvfb :1 -screen 0 640x480x24 -nolisten tcp -audit 4 -auth X1.cfg & export DISPLAY=:1
Of course, you could try high resolution like 1024x768x24

7. Now you can run html2image, it should work
./html2image www.google.com a.jpg

Check if the a.jpg is created successfully

How to use html2image linux on Fedora 8 x86_64

Here is detailed example on how to use html2image linux on Fedora 8 64 bit. This serves as a good example on how to use html2image. Other 64 bit Linux distribution can be done similarly.

1. Install Fedora 8 x86_64

2. Login into the server (you can use the text mode login here. This is suitable for headless server as well)

3. Enter a folder, download html2image

wget http://www.guangmingsoft.net/htmlsnapshot/html2image.i386.tar.gz

4. Extract html2image

tar xvzf html2image.i386.tar.gz
cd html2image
export LD_LIBRARY_PATH=./

5. Install Xvfb coming with the Fedora 8

su root

yum install Xvfb

6. Run Xvfb

Xvfb :1 -screen 0 640x480x24 -nolisten tcp -audit 4 -auth X1.cfg & export DISPLAY=:1
Of course, you could try high resolution like 1024x768x24

7. Now you can run html2image, it should work
./html2image www.google.com a.jpg

Check if the a.jpg is created successfully

Use html2image linux with CGI program like php:

How to use html2image Linux in php script:

1. Extract the new package to a folder (for exampe /html2image)

2. add the folder path (/html2image) to /etc/ld.so.conf
run ldconfig on command line to enable the changes.

3. run nweb
./nweb 8181 /html2image

the small web server for html to image is started.

4. You can call the web server in php script.
see html2imagetest.php for example. Please change the IP to your server IP.
License:

The Server License costs $299.95 per site. It can be used on one Linux server.





近来在做一个directory,搜集一些个人常用的站点。每个站点都需要一份截图。折腾了一番,选用了khtml2png。khtml2png从2.6.0开始需要Qt library的支持,以下是详细的Requirements:
Requirements For running and compiling you need some libraries and tools. You can find the Debian package names in braces
* g++
* KDE 3.x
* kdelibs for KDE 3.x (kdelibs4-dev)
* zlib (zlib1g-dev)
* cmake
服务器系统是redhat EL4,g++和zlib都是装过的了,尚缺kde&cmake。那就先装罢。
用apt-get安装KDE for redhat

添加几个kde的源,先创建一个新的list

vi /etc/apt/sources.list.d/kde.list

添加如下地址
rpm http://apt.kde-redhat.org/apt/kde-redhat redhat/el4/i386 stable
rpm http://apt.kde-redhat.org/apt/kde-redhat all stable
保存之后,先update一下,然后安装qt,arts,kdelibs,和kdebase
apt-get update
apt-get install qt arts kdelibs kdebase
apt-get dist-upgrade
安装kdelibs for KDE (kdelibs4-dev)

kdelibs4-dev这个包是debian用的,redhat适用的是kdelibs-devel。直接用apt-get安装即可。zlib(zlib1g-dev)也一样,redhat适用的是zlib-devel

安装cmake

wget http://www.cmake.org/files/v2.4/cmake-2.4.7.tar.gz
tar zxvf cmake-2.4.7.tar.gz
cd cmake-2.4.7
./bootstrap
make
make install

cmake的安装需在安装qt之后进行,否则会找不到qt_include_path。
安装khtml2png

wget http://nchc.dl.sourceforge.net/sourceforge/khtml2png/khtml2png-2.6.7a.tar.gz
tar zxvf khtml2png-2.6.7a.tar.gz
cd khtml2png-2.6.7a
./configure
make
make install

即可。

用法

khtml2png2 http://163.com 163_com.png

指定图片尺寸
khtml2png2 --height 1024 --width 768 http://163.com 163_com.png

执行上述指令后,桌面会打开一个浏览器窗口,载入目标页面,截图完成后自行关闭。在没有X或者是ssh连接服务器的情况下,需要再做点别的事情。 启动xfs daemon和X Server
/etc/init.d/xfs start
/usr/X11R6/bin/X :1 &

之后在khtml2png2的指令上加一条
--display :1
即可
批量截图

因为安全级的关系,没有使用PEF让php直接执行指令自动截图。转而加入了手动的因素。 即由php取得需要生成截图的网址列表,再生成一个批处理文件。然后由管理员手动执行。 PHP生成的批处理文件siteslist

#!/bin/sh
khtml2png2 --display :1 http://www.163.com 163_com.png
khtml2png2 --display :1 http://www.google.com google_com.png

每行一条,如有必要可以适当的sleep一下。需要采集截图时,执行如下指令即可

sh sitelist




在 Linux 環境使用 khtml2png 製作網頁縮圖



只要使用 khtml2png 這個小工具, 就能製作如同 HEMiDEMi、BlogMarks.net 所呈現的網頁縮圖.

在 Ubuntu 5.10 環境下 (GNOME) 的安裝過程
在 Fedora Core 3 文字模式 (init 3) 未安裝 X window 環境下的操作
需求套件

Ubuntu: g++, kdelibs4-dev, zlib1g-dev
Fedora Core: gcc-c++, kdelibs-devel, zlib-devel

在 Ubuntu 5.10 環境下 (GNOME) 的安裝過程

sudo su -
cd /usr/local/src
wget http://nchc.dl.sourceforge.net/sourceforge/khtml2png/khtml2png-1.0.3.tar.bz2
tar -jxf khtml2png-1.0.3.tar.bz2
cd khtml2png-1.0.3
./configure --prefix=/usr/local
make
make install

執行檔為: /usr/local/bin/khtml2png

使用範例

khtml2png --width 1024 --height 768 --scaled-width 320 --scaled-height 240 http://www.hinet.net/ hinet.png

以 1024 x 768 的虛擬視窗瀏覽 hinet 首頁, 並將虛擬視窗存成 320 x 240 的 hinet.png 檔

在 Fedora Core 3 文字模式 (init 3) 未安裝 X window 環境下的操作

除前述之需求套件外, 需另外加裝 xorg-x11 (皆以 yum 安裝)
安裝 khtml2png 時, configure 參數為: --prefix=/usr/local --with-qt-dir=/usr/lib/qt-3.3
啟動 xfs daemon: /etc/init.d/xfs start
啟動 X server: /usr/X11R6/bin/X :1 &
執行 khtml2png: 同前述範例, 加上 --display :1 參數即可
ps. 美化虛擬視窗內的中文字型請參考: 從 Fedora Core 3 最小安裝開始

khtml2png's User Agent ID

Mozilla/5.0 (compatible; Konqueror/3.4; Linux) KHTML/3.4.2 (like Gecko)


參考資料:

khtml2png - Make screenshots from webpages
Experts Exchange - HTML: Convert html file to image


http://www.guangmingsoft.net/htmlsnapshot/html2image.htm#Support
http://hi.baidu.com/imdao/blog/item/73906081665b1ddebc3e1ee3.html
http://www.guangmingsoft.net/htmlsnapshot/html2image.htm#Support

沒有留言:

wibiya widget