<?php
class html2png{
private $filename;
private $pngwidth;
private $pngheight;
private $url_data;
private $url;
public function __construct($url,$widthsize=1024,$heightsize=800,$file = 'index.html'){
$this->url = $url;
$this->filename = $file;
$this->pngwidth = intval($widthsize);
$this->pngheight = intval($heightsize);
$this->url_data = glob($url.'*',GLOB_ONLYDIR);
}
function getData($forcibly = false){
if(!empty($this->url_data)){
$data = array();
$weburl = 'http://'.$_SERVER['SERVER_NAME'].'/';
foreach($this->url_data as $key => $dir_url){
//得到文件夹名
$dirname = substr($dir_url,strlen($this->url));
//PNG文件地址
$pngurl = $dir_url.DIRECTORY_SEPARATOR.$dirname.'.png';
//HTML文件地址
$fileurl = $dir_url.'/'.$this->filename;
if(file_exists($fileurl)){
if(!file_exists($pngurl) || $forcibly){
system($this->getExec($weburl.$fileurl, $pngurl));
}
if(file_exists($pngurl)){
$data[$dirname] = $this->url . $dirname.'.png';
}
}
}
return empty($data) ? false : $data;
}else{
return false;
}
}
//判断操作系统平台,返回不同的CutyCapt语句
function getExec($weburl,$saveurl){
if(preg_match("/WIN/i",PHP_OS)){
$execurl = dirname(__FILE__).DIRECTORY_SEPARATOR."CutyCapt".DIRECTORY_SEPARATOR."CutyCapt.exe";
$execurl .= " --min-width=".$this->pngwidth." --min-height=".$this->pngheight." --url=".$weburl." --out=".$saveurl;
}elseif(PHP_OS=='Linux'){
$execurl = "xvfb-run --server-args=\"-screen 0, 1024x768x24\" cutycapt";
$execurl .= " --min-width=".$this->pngwidth." --min-height=".$this->pngheight." --url=".$weburl." --out=".$saveurl;
}
return $execurl ;
}
}
$aa = new html2png('templates/');
$fdff = $aa->getData();
print_r($fdff);
?>
没有合适的资源?快使用搜索试试~ 我知道了~
PHP 读取网站HTML代码 生成PNG图片的类
共16个文件
html:7个
png:6个
lnk:1个
3星 · 超过75%的资源 需积分: 31 314 下载量 146 浏览量
2013-12-11
20:16:28
上传
评论 2
收藏 6.35MB RAR 举报
温馨提示
PHP代码 这个类是朋友有需要,自己才研究写的,自己才学PHP3个月多一点. 不是老鸟,代码不规范,不简练的地方还平高手大大们在评论里多指点小弟一二.. 类的功能很简单 根据给的目录地址 得到所有的文件夹下的一个HTML文件. 之后调用html2png访问这个网站的URL路径. 之后生成PDF后转成PNG图片.
资源推荐
资源详情
资源评论
收起资源包目录
html2png.rar (16个子文件)
templates
321
321.png 5KB
index.html 0B
123
index.html 0B
123.png 2KB
23456
23456.png 398KB
index.html 54KB
12345
index.html 0B
12345.png 2KB
34567
34567.png 2KB
index.html 0B
23
4444444444
index
index.html 0B
23 - 快捷方式.lnk 1007B
index.html 0B
23.png 2KB
CutyCapt
CutyCapt.exe 20.87MB
image.php 2KB
共 16 条
- 1
a827887
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页