从网址获取网站图像



我尝试在Windows 7上使用Snappy(src - http://www.codediesel.com/downloads/snappy)和wkhtmltoimage(src - http://code.google.com/p/wkhtmltopd)从URL获取图像,但每次我得到

错误

:图像无法显示,因为它包含错误

法典:

<?php
require_once('Snappy/Media.php');
require_once('Snappy/Image.php');
/* 'wkhtmltoimage' executable  is located in the current directory */
$snap = new Image('C://"Program Files"/wkhtmltopdf/wkhtmltopdf.exe');
/* Displays the bbc.com website index page screen-shot in the browser */
header("Content-Type: image/jpeg");
$snap->output('http://www.bbc.com bbc.jpg');
?>

我不确定你在用什么,但 http://www.artviper.net/website-tools/website-thumbnails.php 有一个不错的网站。您甚至可以简单地自定义其链接以显示任何网站。不过加载需要一段时间。所以我建议将它们保存在本地

您甚至可以自定义输出宽度和浏览器宽度/高度。

简单的示例代码,用于将它们保存在本地并显示图像:

<?php
$site = $_POST['site'];
if (strlen($site)==0)
  $site = "www.stackoverflow.com";
$url = "http://85.25.9.83/artviper.php?w=360&sdx=1024&q=90&userID=AV_47845683_352324_2FC&url=".urlencode($site);
$content = implode('', file($url));
file_put_contents("myimage.jpg", $content);
?>
<form method="POST">
<input type="text" name='site' value='<?php echo $site; ?>'/>
<input type="submit" value="Show image" />
</form>
<img src='myimage.jpg' />

最新更新