當初會想要使用這個功能,是不打算讓使用者自行上傳網站圖片,可能會出現使用者亂上傳或不上傳,而不上傳又會造成資訊不完整,所以只能限制用程式來自動產生嘍!
找了許多資料,發現在Windows環境下的Apache Server可以輕鬆完成,利用IE + com元件可以輕鬆拍照成功,例如:WebPageGrabber(imagegrabwindow),但是在Linux上,卻無該方法可以使用,在遍尋不著範例之下,只有自己整合資料來達成了,我發現了許多人事實上有實作,但是卻沒有很完整的交待所有有可能在安裝時所發生的問題,基於我很健忘的理由,所以又把他記錄在BLOG上,順便可以回憶,也可以分享給大家!
測試套件:
CutyCapt
http://cutycapt.sourceforge.net/
註:他很簡單的說明了一下,但是安裝時問題蠻多的,所以才會產生這篇!
實作環境:
Linux Fedora Core 9
Without X Server
需求安裝:
Qt
gcc-c++
subversion
安裝步驟:
1、首先利用Yum套件安裝以下所有套件
# yum -y install subversion qt-devel qt-config SDL-devel gcc-c++ Xvfb
2、切換至您想安裝存放的目錄
# mkdir /path-to-you-want-to-installed
# cd /path-to-you-want-to-installed
(/path-to-you-want-to-installed 是由您自行決定命名)
3、取得CutyCapt套件並存放至指定目錄
# svn co https://cutycapt.svn.sourceforge.net/svnroot/cutycapt
4、進入安裝目錄
# cd cutycapt/CutyCapt
5、執行安裝
這裡需要qmake跟g++套件,已經在第一步驟全部安裝。
# /usr/local/bin/qmake
# make
6、設定xvfb-run
這裡我並不知道為什麼他沒有自動預設安裝,但可以在Source裡找到,這裡已經有提供,請下載回去解開後將其放至 /usr/local/bin裡以利套作使用(此為使用者無進入 X Server時使用,因為是要給網站程式用,所以必須一定要使用此方法來虛擬運行並利用qt拍照)
# mv xvfb-run /usr/local/bin
# chmod +x /usr/local/bin/xvfb-run
下載:xvfb-run.rar
安裝完畢。
使用方法:
使用指令為
/usr/local/bin/xvfb-run /path-to-you-want-to-installed/cutycapt/CutyCapt/CutyCapt -f /tmp/path-to-your-temp --url=http://you.want.to.photo --out=/out-photo-to-dir-name
產生全站大小約需15~20秒左右,以下有其它參數資料,請參考:
% CutyCapt --help
-----------------------------------------------------------------------------
Usage: CutyCapt --url=http://www.example.org/ --out=localfile.png
-----------------------------------------------------------------------------
--help Print this help page and exit
--url=<url> The URL to capture (http:...|file:...|...)
--out=<path> The target file (.png|pdf|ps|svg|jpeg|...)
--out-format=<f> Like extension in --out, overrides heuristic
--min-width=<int> Minimal width for the image (default: 800)
--max-wait=<ms> Don't wait more than (default: 90000, inf: 0)
--delay=<ms> After successful load, wait (default: 0)
--user-styles=<url> Location of user style sheet, if any
--header=<name>:<value> request header; repeatable; some can't be set
--method=<get|post|put> Specifies the request method (default: get)
--body-string=<string> Unencoded request body (default: none)
--body-base64=<base64> Base64-encoded request body (default: none)
--app-name=<name> appName used in User-Agent; default is none
--app-version=<version> appVers used in User-Agent; default is none
--user-agent=<string> Override the User-Agent header Qt would set
--javascript=<on|off> JavaScript execution (default: on)
--java=<on|off> Java execution (default: unknown)
--plugins=<on|off> Plugin execution (default: unknown)
--private-browsing=<on|off> Private browsing (default: unknown)
--auto-load-images=<on|off> Automatic image loading (default: on)
--js-can-open-windows=<on|off> Script can open windows? (default: unknown)
--js-can-access-clipboard=<on|off> Script clipboard privs (default: unknown)
-----------------------------------------------------------------------------
<f> is svg,ps,pdf,itext,html,rtree,png,jpeg,mng,tiff,gif,bmp,ppm,xbm,xpm
-----------------------------------------------------------------------------
http://cutycapt.sf.net - (c) 2003-2008 Bjoern Hoehrmann - bjoern@hoehrmann.de
那要如何使用在PHP上呢,請看一個小範例....
<?php
// 要截圖的網址URL
$url = 'http://you.want.to.photo/';
// 要輸出的路徑
$outpath = /out-photo-to-dir-name/
// 要輸出的圖片名
$outname = 'test.png'; // 也可以用 .jpg等其它格式
// 程式定義
$progpath = '/usr/local/bin/xvfb-run /path-to-you-want-to-installed/cutycapt/CutyCapt/CutyCapt';
$cmd = "$progpath --url=$url --out=$outpath/$outname";
exec($cmd);
?>
搞定....收工.....




