以前一直在找PHP网站截屏实现方法的代码,现在终于找到了。把他搬过来。自己也没试过,用的时候在捣鼓捣鼓吧。
其他方法:1、http:///screenshot/ 这里有接口,可自己调用
2、php利用CutyCapt实现网页高清截图
->http:///tech/php/273577.shtml
phantomjs和slimerjs,两款都是服务器端的js,简单说来,都是封装了浏览器解析引擎,不同是phantomjs封装的
webkti,slimerjs封装的是Gecko(firefox)。 权衡利弊,决定研究下phantomjs,于是就用phantomjs实现了网
站快照生成。phantomjs的项目地址是:http:///
代码涉及两个部分,一个是设计业务的index.php,另一个是生成快照的js脚本snapshot.js。代码比较简单,仅仅是实现了功能,没有做过多的修饰。代码分别如下所示:
<?php
if
(isset($_GET['url']))
{
set_time_limit(0);
$url = trim($_GET['url']);
$filePath = "./cache/".md5($url).'.png';
if (is_file($filePath))
{
exit($filePath);
}
$command = "phantomjs/bin/phantomjs snapshot.js {$url}
{$filePath}";
exec($command);
exit($filePath);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,
initial-scale=1.0" />
<meta name="keywords" content=""
/>
<meta name="description" content=""
/>
<title>快照生成</title>
<script
src="http://code./jquery-1.8.3.min.js"></script>
<style>
* {
margin:
0;
padding:
0;
}
form {
padding:
20px;
}
div {
margin: 20px
0 0;
}
input {
width:
200px;
padding: 4px
2px;
}
#placeholder {
display:
none;
}
</style>
</head>
<body>
<form action="" id="form">
<input type="text" id="url" />
<button
type="submit">生成快照</button>
<div>
<img src="" alt="" id="placeholder"
/>
</div>
</form>
<script>
$(function(){
$('#form').submit(function(){
if (typeof($(this).data('generate')) !== 'undefined'
&& $(this).data('generate') ===
true)
{
alert('正在生成网站快照,请耐心等待...');
return false;
}
$(this).data('generate', true); |