LoginSignup
14

More than 5 years have passed since last update.

wkhtmltoimageでテキストとhtmlを画像に変換する

Last updated at Posted at 2015-09-28

インストール

sudo wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2.1/wkhtmltox-0.12.2.1_linux-centos6-amd64.rpm
# インストールしないと「error: Failed dependencies」
sudo yum install xorg-x11-fonts-75dpi.noarch
sudo rpm -ivh wkhtmltox-0.12.2.1_linux-centos6-amd64.rpm

ローカルのhtmlファイルをjpgに変換

wkhtmltoimage input.html output.jpg
  • 他にもtif, png, bmpも可能(gifはエラーになった)

ローカルのtextファイルをjpgに変換

wkhtmltoimage input.txt output.jpg

URLを指定して変換

wkhtmltoimage http://google.com google.jpg

URLを指定して変換(proxy指定)

wkhtmltoimage --proxy http://user:password@proxyhost.com https://www.google.com google.jpg

文字コードを指定(--encoding)

wkhtmltoimage --encoding shift_jis input.txt output.jpg

サイズを指定(--height, --width)

wkhtmltoimage --height 100 --width 50 input.txt output.jpg
  • 拡大・縮小はしないので、小さいサイズだと切れる場合がある

フォントサイズを指定(--minimum-font-size)

wkhtmltoimage --minimum-font-size 30 input.txt output.jpg
  • minimumはあるけどmaxは無い模様

javascriptを無効(--disable-javascript)

wkhtmltoimage --disable-javascript http://google.com google.jpg

wkhtmltopdfにはあるが、wkhtmltoimageに無いパラメータ

  • --print-media-type
  • --page-size
  • --orientation

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14