ScreenshotOne.com API 的 PHP SDK,用于截图任何 URL

v1.0.5 2024-09-22 17:27 UTC

This package is not auto-updated.

Last update: 2024-09-22 17:29:52 UTC


README

Build

官方 PHP 截图 API 客户端。

开始截图只需几分钟。只需 注册 获取访问权限和密钥,导入客户端,即可开始使用。

SDK 客户端与最新的 截图 API 选项 保持同步。

安装

composer require screenshotone/sdk:^1.0

用法

生成截图 URL 而不执行请求。或者下载截图。由您决定

<?php 

// If you don't use Composer in your project, please, read https://getcomposer.org.cn/doc/01-basic-usage.md#autoloading. 
// You need the Composer autoloader to use the API SDK.

// ...

use ScreenshotOne\Sdk\Client;
use ScreenshotOne\Sdk\TakeOptions;

$client = new Client('M73PaLOC8lchKQ', 'VjuscNqAfGCC4A');

$options = TakeOptions::url("https://example.com")
    ->fullPage(true)
    ->delay(2)
    ->geolocationLatitude(48.857648)
    ->geolocationLongitude(2.294677)
    ->geolocationAccuracy(50);

$url = $client->generateTakeUrl($options);
echo $url.PHP_EOL;
// expected output: https://api.screenshotone.com/take?url=https%3A%2F%2Fexample.com...

$image = $client->take($options);
file_put_contents('example.png', $image);

测试

运行

$ composer run-script tests

或者

$ vendor/bin/phpunit

许可证

screenshotone/phpsdk 采用 MIT 许可证 发布。