Skip to content


安装wkhtmltopdf让php在linux环境下给网站截屏

http://wkhtmltopdf.org/obsolete-downloads.html
新版本依赖包比较多,我是centos5.8系统,这里使用64位老版本,同时它还用windows下的版本
wget http://download.gna.org/wkhtmltopdf/obsolete/linux/wkhtmltoimage-0.10.0_rc2-static-amd64.tar.bz2

tar -jxvf wkhtmltoimage-0.10.0_rc2-static-amd64.tar.bz2

解压后就可使用
./wkhtmltoimage-amd64 –help

  1. Name:
  2.   wkhtmltoimage 0.10.0 rc2
  3.  
  4. Synopsis:
  5.   wkhtmltoimage [OPTIONS]... <input file> <output file>
  6.  
  7. Description:
  8.   Converts an HTML page into an image,
  9.  
  10. General Options:
  11.       --crop-h <int>                  Set height for croping
  12.       --crop-w <int>                  Set width for croping
  13.       --crop-x <int>                  Set x coordinate for croping
  14.       --crop-y <int>                  Set y coordinate for croping
  15.   -H, --extended-help                 Display more extensive help, detailing
  16.                                       less common command switches
  17.   -f, --format <format>               Output file format (default is jpg)
  18.       --height <int>                  Set screen height (default is calculated
  19.                                       from page content) (default 0)
  20.   -h, --help                          Display help
  21.       --quality <int>                 Output image quality (between 0 and 100)
  22.                                       (default 94)
  23.   -V, --version                       Output version information an exit
  24.       --width <int>                   Set screen width (default is 1024)
  25.                                       (default 1024)
  26.  
  27. Contact:
  28.   If you experience bugs or want to request new features please visit
  29.   <http://code.google.com/p/wkhtmltopdf/issues/list>, if you have any problems
  30.   or comments please feel free to contact me: <uuf6429@gmail.com>

./wkhtmltoimage-amd64 http://www.baidu.com baidu.jpg
Loading page (1/2)
Rendering (2/2)
Done

截一张1024*1024 质量为35的jpg图片
./wkhtmltoimage-amd64 –crop-h 1024 –crop-w 1024 –quality 35 http://blog.c1gstudio.com c1g.jpg

c1gstudio

和php结合
cp wkhtmltoimage-amd64 /opt/toolkits/
chown www:website /opt/toolkits/wkhtmltoimage-adm64
chmod 550 /opt/toolkits/wkhtmltoimage-adm64

vi /opt/php/etc/php.ini
open_basedir = “/opt/htdocs:/tmp/session:/tmp/upload:/opt/php/PEAR:/opt/php/lib/php:/opt/toolkits/”

重启phpfpm
/opt/php/sbin/php-fpm restart

vi test.php

Posted in Others.

Tagged with .


No Responses (yet)

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.