现在的位置: 首页 > 综合 > 正文

使用PHP 给网站 生成快照图片和缩略图

2013年08月15日 ⁄ 综合 ⁄ 共 1769字 ⁄ 字号 评论关闭

使用PHP 给网站 生成快照图片和缩略图 

因为做网站综合信息查询 需要用到这个 
搜索了一下国外的的解决方案 
大部分是使用对方API来实现的 
但是这种方式不太好 
1是会被对方加上水印, 缩略图被加水印不太好 
2免费提供的有生成限制,收费的太贵了 一般$1 = 可以生成10个缩略图 
像我这种要生成大约9千万以上缩略图的 感觉不太靠谱 费用太贵 而且缩略图都被人家水印了 

最后决定还是 使用第三方的开源软件 自建 
这样网站快照生成后 可以自动上传到又拍云里 调用速度快 

暂时测试的这个方案 无问题 

http://code.google.com/p/wkhtmltopdf/downloads/list 

32位的下载 
wkhtmltoimage-0.11.0_rc1 Linux Static Binary (i368) 
64位的下载 
wkhtmltoimage-0.11.0_rc1 Linux Static Binary (AMD64) 
这个是已编译的静态可执行文件 比较简单和方便 


依赖qt4包

解压 
tar -xvf ***.tar.bz2 
移动下目录 然后直接PHP调用 
比如 /sbin/wkhtmltoimage 
先测试 /sbin/wkhtmltoimage google.com g.jpg 

建议将清晰度设置的低点 
我测试了 如果不调的话 
Google的页面 生成了PNG大小是1M多 JPG是400多K 

PHP里直接 exec就可以调用生成 然后做图片处理 

然后在使用php的gd或者im 
php使用GD或者IM的图片处理模块处理 就可以了 
可以加缩略图的水印等等 

还在测试其他的开源方案 
可以提供REST接口的 
到时候在更新 

------------------------------------- 

国外有很多网站,会提供的URL地址的预览功能,鼠标移到URL地址上,就自动显示网站的缩略图。 

我看用 wkhtmltopdf 来实现正合适,而且提供了 Windows、Linux 和 Mac 平台上的版本。 

该工具的详细参数如下: 

General Options: 
      --crop-h <int>                  Set height for croping 
      --crop-w <int>                  Set width for croping 
      --crop-x <int>                  Set x coordinate for croping 
      --crop-y <int>                  Set y coordinate for croping 
  -H, --extended-help                 Display more extensive help, detailing less common command switches 
  -f, --format <format>               Output file format (default is jpg) 
  -h, --help                          Display help 
      --quality <int>                 Output image quality (between 0 and 100)    (default 94) 
  -V, --version                       Output version information an exit 
      --width <int>                   Set screen width (default is 1024)   (default 1024) 



--------------------------- 

tar下载地址: 
http://code.google.com/p/wkhtmltopdf/downloads/list 

相关链接 
http://blog.cnlabs.net/?p=2625 
http://blog.cnlabs.net/?p=2636 
http://brooky.cc/2011/05/26/convert-html-to-image-and-pdf/ 
http://www.oschina.net/question/12_10653 

【上篇】
【下篇】

抱歉!评论已关闭.