codegyre/phantomshot

使用 PhantomJS 制作网页快照的 PHP 工具

安装: 703

依赖: 0

建议者: 0

安全: 0

星星: 24

关注者: 4

分支: 2

开放问题: 0

语言:JavaScript

dev-master 2014-01-22 02:01 UTC

This package is not auto-updated.

Last update: 2024-09-23 13:57:36 UTC


README

使用 PhantomJS 制作网页快照的 PHP 工具

安装

添加 composer 需求

"require": {
    "codegyre/phantomshot": "dev-master"
}

在 composer.json 中添加 post-install 和 post-update 钩子

"scripts": {
    "post-install-cmd": [
        "Codegyre\\PhantomShot\\ComposerHook::hook"
    ],
    "post-update-cmd": [
        "Codegyre\\PhantomShot\\ComposerHook::hook"
    ]
}

我们需要这样做,通过 npm 安装所需的依赖项。

制作网页快照

$webPage = new \Codegyre\PhantomShot\WebPage('http://github.com');
$webPage->getShot('/tmp/github.png');

缩略图

$tc = new \Codegyre\PhantomShot\ThumbnailCollector('http://github.com');
$tc->createThumbnail('/destination/dir/1.png', 200, 400, ThumbnailCollector::TRANSFORM_FILL_HEIGHT_MIDDLE);
$tc->createThumbnail('/destination/dir/1.png', 350, 160, ThumbnailCollector::TRANSFORM_FILL_WIDTH_MIDDLE);

确保您系统中已安装 npm

作为服务使用

您可以使用 phantomshot 作为 Web 服务来获取网站截图

cd src/js && ./phantomshot-service.js --port=3000

它将在 localhost:3000 上启动 HTTP 服务器。用法

http://localhost:3000/?width=1024&height=768&url=http://example.com