stechstudio / snapthis
SnapThis 截图服务的 PHP SDK
0.5
2021-03-18 12:17 UTC
Requires
- php: ^7.2|^8.0
- stechstudio/laravel-record: ^1.5
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.3
README
SnapThis 是一种截图服务,可以将 URL 或 HTML 有效负载转换为 PNG 图像或 PDF 文件。
安装
您可以通过 composer 安装此包
composer require stechstudio/snapthis
将 API 密钥存储在 .env 文件中
SNAPTHIS_API_KEY=[your api key]
快速入门
使用 snapshot
或 pdf
方法进行截图。从控制器方法返回此结果以重定向到截图
use SnapThis; // Will take a PNG image snapshot and redirect the user: return SnapThis::snapshot('https://laravel.net.cn');
或者添加 download
方法强制用户下载截图。
return SnapThis::pdf('https://laravel.net.cn')->download();
要获取原始二进制内容,请使用 contents
方法
$contents = SnapThis::pdf('https://laravel.net.cn')->contents();
您可以使用 HTML 字符串代替 URL
SnapThis::pdf("<strong>Hello there</strong>");
您还可以传递一个 blade 视图,然后简单地将 snapshot
或 pdf
方法链在一起。
$users = User::all(); return SnapThis::view('reports.users', ['users' => $users])->pdf();
选项
有许多选项可以自定义截图。文档即将推出!
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件。