dotzero/yii-phantomjs-screenshot

此包已被废弃且不再维护。未建议替代包。

Yii PhantomjsWebpageScreenshot 扩展,允许实时生成网页截图

v1.0.0 2016-04-30 08:23 UTC

This package is auto-updated.

Last update: 2022-06-04 08:34:21 UTC


README

Latest Stable Version License

Yii PhantomjsWebpageScreenshot 扩展允许实时生成网页截图。它使用无头 Webkit PhantomJS 作为捕获引擎。

PhantomJS 是一个带有 JavaScript API 的无头 WebKit。它对各种网络标准具有快速且本地的支持:DOM 处理、CSS 选择器、JSON、Canvas 和 SVG。

要求

安装

通过 composer

$ composer require dotzero/yii-phantomjs-screenshot

将供应商路径添加到配置文件中,附加组件并设置属性。

'aliases' => array(
    ...
    'vendor' => realpath(__DIR__ . '/../../vendor'),
),
'components' => array(
    ...
    'screenshot' => array(
        'class' => 'vendor.dotzero.yii-phantomjs-screenshot.EWebpageScreenshot',
        //'phantomjs' => '/bin/phantomjs',
        //'width' => 640,
        //'height' => 480,
    ),
),

使用方法

$screenshot = Yii::app()->screenshot;
$screenshot->width = 640;
$screenshot->height = 480;

$url = 'http://www.google.com';
$outfile = Yii::getPathOfAlias('application.runtime') . '/' . uniqid() . '.png';

$screenshot->capture($url, $outfile);

许可

在 MIT 许可下发布:https://open-source.org.cn/licenses/mit-license.php