Linux環境でスクリーンショット
こちらを参考にして、khtml2png をCentos5.2にインストールしてみました。
http://d.hatena.ne.jp/holidayworking/20081124/1227501839
必要なソフトをインストール
yum install gcc gcc-c++ automake autoconf nano zlib zlib-devel yum groupinstall "X Window System" "KDE (K Desktop Environment)" yum install kdelibs kdelibs-devel yum install Xvfb xorg "xorg-x11-font*" yum install cmake
参考サイトには、書いてませんでしたが、
以下のソフトも必要ならいてれおいたほうがいいかも。
yum groupinstall "KDE Software Development" yum install kdelibs4-dev
khtml2png は、yum でインストールできないので、ファイルをダウンロード
wget http://downloads.sourceforge.net/khtml2png/khtml2png-2.7.6.tar.gz?modtime=1224606904&big_mirror=0 tar zxvf khtml2png-2.7.6.tar.gz cd khtml2png-2.7.6 ./configure make make install
ここで ./configure の時に、 QT_INCLUDE_DIR を設定しろと、エラーが出た人は、
configure を以下のように書き換えてください。
vi configure 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 .
これでたぶん、makeまでいけると思います。
インストールが一通り終わったら、Xvfbを起動する。
Xvfb :2 -screen 0 1024x768x24& export DISPLAY=localhost:2.0
ここで、以下のようなエラーが出るかもしれないが無視する
Could not init font path element unix/:7100, removing from list!
ようやくスクリーンショットをとる準備ができたので
とりあえず、yahoo のトップページを見てみる
khtml2png2 --get-body http://www.yahoo.co.jp yahoo.png
なんかつらつらとエラーが出るが気にしない
DCOPClient::attachInternal. Attach failed Could not open network socket kbuildsycoca running... ScimInputContextPlugin() ~ScimInputContextPlugin()
対応外のブラウザだと、こんな風にyahooが見えるんですね。
その他、以下のようなメッセージも出たがとりあえず気にしない。
FreeFontPath: FPE "built-ins" refcount is 2, should be 1; fixing. Could not init font path element unix/:7100, removing from list!
参考のサイトにも書いてありますが、
Cookieとか、Javascriptの設定で、うまくスクリーンショトが表示されない場合は
以下のファイルを修正する。
cd ~/.kde/share/config vi kcookiejarrc [$Version] update_info=kcookiescfg.upd:kde2.2/b1,kcookiescfg.upd:kde3.1/cvs [Cookie Dialog] PreferredPolicy=2 ShowCookieDetails=false [Cookie Policy] CookieDomainAdvice= CookieGlobalAdvice=Accept
vi khtml2pngrc [HTML Settings] AutomaticDetectionLanguage=0 [Java/JavaScript Settings] PopupBlockerPassivePopup=false
意外と、HTMLのレンダリングがきれいで、崩れている部分も少ない気がします。
フォントとか、ちゃんといれたら文字ももっときれいに表示されるでしょう。
FireFoxとかでも、同様のスクリーンショットがとれるらしいですが
こっちのほうが、お手軽な気がします。
オプション一覧
khtml2png2 --help Usage: khtml2png2 [Qt-options] [KDE-options] [options] url outfile Render HTML to a PNG from the command line Example: khtml2png2 --width 800 --height 600 http://www.kde.org/ kde-org.png or khtml2png --auto ID_border http://www.kde.org/ kde-org.png Generic options: --help Show help about options --help-qt Show Qt specific options --help-kde Show KDE specific options --help-all Show all options --author Show author information -v, --version Show version information --license Show license information -- End of options Options: -w, --width <width> Width of canvas on which to render html [800] -h, --height <height> Height of canvas on which to render html [600] --sw, --scaled-width <width> Width of image to produce [] --sh, --scaled-height <height> Height of image to produce [] -t, --time <time> Maximum time in seconds to spend loading page [30] --auto <id> Use this option if you to autodetect the bottom/right border [] --get-body Autodected the body of the page (if width is not detected, use --width) -b, --disable-window If set, don't show the window when doing rendering (can lead to missing items) --disable-js Enable/Disable javascript (enabled by default) --disable-java Enable/Disable java (enabled by default) --disable-plugins Enable/Disable KHTML plugins (like Flash player, enabled by default) --disable-redirect Enable/Disable auto-redirect by header <meta > (enabled by default) --disable-popupkiller Enable/Disable popup auto-kill (enabled by default) Arguments: url URL of page to render outfile Output file
スクロール画面も最後までスクリーン取ってくれるオプション、 --get-body が結構重宝するかも
Window環境でも、スクロールまで対応してスクリーンショット取ってくれるソフトは少ないからね。
指定の画像サイズで保存したい場合は、 -w -h --sw --sh あたりを駆使すればできそうな感じかな。
開発中のWebサイトの進捗を自動で画像に変換して、PDFとかに出力するとか
してみようかと考えています。
特に、画面イメージをみんなで共有する時に、
印刷したり、PowerPointに貼るのに、役に立ちそう。
あとサイトマップを作るときに、画面イメージをサムネイルとして
出力するのもいいかも。