screenshotmachine/screenshotmachine-php
Composer 安装命令:
composer require screenshotmachine/screenshotmachine-php
包简介
Captures website screenshot and converts website to PDF using Screenshot machine - online website screenshot generator and website to PDF converter.
关键字:
README 文档
README
Captures website screenshot and converts website to PDF using Screenshot machine - online website screenshot generator and website to PDF converter.
Installation
a) using Composer - package manager for PHP
php composer.phar require screenshotmachine/screenshotmachine-php
b) or download source code directly from GitHub.com
First, you need to create a free/premium account at www.screenshotmachine.com website. After registration, you will see your customer key in your user profile. Also secret phrase is maintained here. Please, use secret phrase always, when your API calls are called from publicly available websites.
Set-up your customer key and secret phrase (if needed) in the script:
$customer_key = "PUT_YOUR_CUSTOMER_KEY_HERE"; $secret_phrase = ""; //leave secret phrase empty, if not needed
Website screenshot API
Set additional options to fulfill your needs:
//mandatory parameter $options['url'] = "https://www.google.com"; // all next parameters are optional, see our website screenshot API guide for more details $options['dimension'] = "1366x768"; // or "1366xfull" for full length screenshot $options['device'] = "desktop"; $options['format'] = "png"; $options['cacheLimit'] = "0"; $options['delay'] = "200"; $options['zoom'] = "100";
More info about options can be found in our Website screenshot API.
Sample code
<?php $customer_key = "PUT_YOUR_CUSTOMER_KEY_HERE"; $secret_phrase = ""; //leave secret phrase empty, if not needed $machine = new ScreenshotMachine($customer_key, $secret_phrase); //mandatory parameter $options['url'] = "https://www.google.com"; // all next parameters are optional, see our website screenshot API guide for more details $options['dimension'] = "1366x768"; // or "1366xfull" for full length screenshot $options['device'] = "desktop"; $options['format'] = "png"; $options['cacheLimit'] = "0"; $options['delay'] = "200"; $options['zoom'] = "100"; $api_url = $machine->generate_screenshot_api_url($options); //put link to your html code echo '<img src="' . $api_url . '">' . PHP_EOL;
Generated api_url link can be placed in <img> tag or used in your business logic later.
If you need to store captured screenshot as an image, just call:
<?php $customer_key = "PUT_YOUR_CUSTOMER_KEY_HERE"; $secret_phrase = ""; //leave secret phrase empty, if not needed $machine = new ScreenshotMachine($customer_key, $secret_phrase); //mandatory parameter $options['url'] = "https://www.google.com"; // all next parameters are optional, see our website screenshot API guide for more details $options['dimension'] = "1366x768"; // or "1366xfull" for full length screenshot $options['device'] = "desktop"; $options['format'] = "png"; $options['cacheLimit'] = "0"; $options['delay'] = "200"; $options['zoom'] = "100"; $api_url = $machine->generate_screenshot_api_url($options); //save screenshot as an image $output_file = 'output.png'; file_put_contents($output_file, file_get_contents($api_url)); echo 'Screenshot saved as ' . $output_file . PHP_EOL;
Captured screenshot will be saved as output.png file in current directory.
Website to PDF API
Set the PDF options:
//mandatory parameter $options['url'] = "https://www.google.com"; // all next parameters are optional, see our website to PDF API guide for more details $options['paper'] = "letter"; $options['orientation'] = "portrait"; $options['media'] = "print"; $options['bg'] = "nobg"; $options['delay'] = "2000"; $options['scale'] = "50";
More info about options can be found in our Website to PDF API.
Sample code
$customer_key = "PUT_YOUR_CUSTOMER_KEY_HERE"; $secret_phrase = ""; //leave secret phrase empty, if not needed $machine = new ScreenshotMachine($customer_key, $secret_phrase); //mandatory parameter $options['url'] = "https://www.google.com"; // all next parameters are optional, see our website to PDF API guide for more details $options['paper'] = "letter"; $options['orientation'] = "portrait"; $options['media'] = "print"; $options['bg'] = "nobg"; $options['delay'] = "2000"; $options['scale'] = "50"; $pdf_api_url = $machine->generate_pdf_api_url($options); //save PDF file $output_file = 'output.pdf'; file_put_contents($output_file, file_get_contents($pdf_api_url)); echo 'PDF saved as ' . $output_file . PHP_EOL;
Captured PDF will be saved as output.pdf file in the current directory.
License
The MIT License (MIT)
screenshotmachine/screenshotmachine-php 适用场景与选型建议
screenshotmachine/screenshotmachine-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12.89k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2019 年 07 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「pdf」 「thumbnail」 「snapshot」 「headless」 「html2pdf」 「webpage」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 screenshotmachine/screenshotmachine-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 screenshotmachine/screenshotmachine-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 screenshotmachine/screenshotmachine-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PDF or Image generation from a Url or HTML page
Guzzle Snapshots Middleware
A PHP package that takes a snapshot of your application and allows you to retrieve it later to help with debugging.
A PHP library for fetching thumbnails from a URL
Snapshot your database with mysqldump and store it to a an asset volume (S3). Also restore it from that same location. Great for local dev snapshots and nightly backups.
A Gokaru storage & thumbnail server PHP client
统计信息
- 总下载量: 12.89k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-07-23