yongfook / bannerbear
Bannerbear API的PHP包装器 - 图片和视频生成服务
Requires
- php: >=7.1.0
- ext-curl: *
Requires (Dev)
- phpstan/phpstan: ^1.2
This package is not auto-updated.
Last update: 2024-09-20 17:53:46 UTC
README
Bannerbear API的PHP包装器 - 图片和视频生成服务。
文档
完整的API文档请见此处
要求
PHP 7.4或更高版本
安装
使用以下命令安装包
composer require yongfook/bannerbear
要使用绑定,通过Autoload加载
require_once('vendor/autoload.php');
用法
目录
请注意,所有方法都返回字典/关联数组。响应可以在开发者文档此处找到。
身份验证
在Bannerbear中获取您项目的API密钥,然后实例化一个新的客户端。
$bb = new Bannerbear\BannerbearClient("your api key");
或者,将API密钥设置在名为BANNERBEAR_API_KEY
的环境变量中。
$bb = new Bannerbear\BannerbearClient();
账户信息
返回与API密钥关联的账户或项目的信息。
$account = $bb->account();
图片
创建图片
要创建图片,您需要引用一个模板UID和一系列修改。默认为异步生成,意味着API将响应pending
状态,您可以使用get_image
来检索最终图片。
$bb->create_image("template uid", [ "modifications" => [ [ "name" => "headline", "text" => "Hello world!", ], [ "name" => "photo", "image_url" => "https://images.unsplash.com/photo-1555400038-63f5ba517a47?w=1000&q=80", ], ], ]);
您也可以同步创建图片 - 这将需要更长的时间来响应,但图片将直接在响应中提供
$bb->create_image( "template uid", [ "modifications" => [ [ "name" => "headline", "text" => "Hello world!", ], [ "name" => "photo", "image_url" => "https://images.unsplash.com/photo-1555400038-63f5ba517a47?w=1000&q=80", ], ], ], TRUE );
选项
modifications
:您想要进行修改的modifications
数组(数组)webhook_url
:要发布最终图片对象的webhook URL(字符串)transparent
:以透明背景渲染图片(布尔值)synchronous
:同步生成图片(布尔值)render_pdf
:除了图片外,还渲染PDF(布尔值)metadata
:包括任何以后引用的元数据(字符串)
获取图片
$bb->get_image("image uid");
列出所有图片
$bb->list_images();
可选地,您可以提供页面和限制
$bb->list_images(10, 25);
视频
创建视频
$bb->create_video("video template uid", [ "input_media_url" => "https://www.yourserver.com/videos/awesome_video.mp4", "modifications" => [ [ "name" => "headline", "text" => "Hello world", ], ], ]);
选项
input_media_url
:要导入的公开视频文件的URL(字符串)modifications
:要修改视频叠加层的修改数组(数组)webhook_url
:要发布最终视频对象的webhook URL(字符串)blur
:从1到10模糊导入的视频(整数)trim_to_length_in_seconds
:将视频裁剪到特定的长度(整数)create_gif_preview
:创建一个简短的预览Gif(布尔值)metadata
:包括任何以后引用的元数据(字符串)
如果您的视频使用“多叠加层”构建包,则可以通过以下方式传递一系列要渲染的帧:
frames
:一组修改的数组(数组)frame_durations
:指定每帧的持续时间(数组)
获取视频
$bb->get_video("video uid");
更新视频
$bb->update_video("video uid", [ "approved" => true, "transcription" => [ "This is a new transcription", "It must contain the same number of lines", "As the previous transcription", ], ]);
选项
approved
:批准视频进行渲染(布尔值)transcription
:表示新转录的字符串数组(将覆盖现有内容)
列出所有视频
$bb->list_videos();
选项
page
:分页(整数
)
集合
在一个API请求中创建多个图像。
$bb->get_collection("collection uid"); $bb->list_collections(3); $bb->create_collection( "template set uid", [ "modifications" => [ [ "name" => "headline", "text" => "Hello World!", ], ], ], true );
create_collection
的选项
modifications
:您想要进行修改的modifications
数组(数组)webhook_url
:一个用于发送最终集合对象的webhook URL(字符串
)transparent
:以透明背景渲染图片(布尔值)synchronous
:同步生成图像(布尔值
)metadata
:包括任何以后引用的元数据(字符串)
动画Gif
创建幻灯片风格的GIF
$bb->get_animated_gif("gif uid") $bb->list_animated_gifs(3) $bb->create_animated_gif("template uid", [ "frames" => [ [ // frame 1 starts here [ "name" => "layer1", "text" => "This is my text" ], [ "name" => "photo", "image_url" => "https//www.pathtomyphoto.com/1.jpg" ] ], [ // frame 2 starts here [ "name" => "layer1", "text" => "This is my follow up text" ], [ "name" => "photo", "image_url" => "https://www.pathtomyphoto.com/2.jpg" ] ] ] ])
create_animated_gif
的选项
frames
:要进行的修改的数组数组(数组
)(请参阅)frame_durations
:每个帧显示的时间(以秒为单位)的数组(数组
)input_media_url
:可选地导入外部视频文件作为GIF的一部分fps
:每秒帧数,例如1(整数
)loop
:是否循环(布尔值
)webhook_url
:一个用于发送最终GIF对象的webhook URL(字符串
)metadata
:包括任何以后引用的元数据(字符串)
电影
将视频剪辑或静态图像组装成带有转场的单个电影。
$bb->get_movie("movie uid"); $bb->list_movies(3); $bb->create_movie([ "width" => 800, "height" => 800, "transition" => "pixelize", "inputs" => [ [ "asset_url" => "https://images.unsplash.com/photo-1635910160061-4b688344bd20?w=500&q=60", ], [ "asset_url" => "https://i.imgur.com/fH7a5dO.png", ], ], ]);
create_movie
的选项
width
:电影宽度(以像素为单位)(整数
)height
:电影高度(以像素为单位)(整数
)transition
:转场样式:淡入淡出、像素化、下拉、向右滑动、上滑、向左滑动(字符串
)inputs
:输入列表(数组
)(请参阅)webhook_url
:一个用于发送最终电影对象的webhook URL(字符串
)metadata
:包括任何以后引用的元数据(字符串)
截图
对网站进行截图。
$bb->get_screenshot("screenshot uid"); $bb->list_screenshots(3); $bb->create_screenshot( "https://www.bannerbear.com/", [ "width" => 1000, ], true );
create_screenshot
的选项
width
:所需截图宽度(以像素为单位)(整数
)height
:所需截图高度(以像素为单位)(整数
)synchronous
:同步生成截图(布尔值
)mobile
:使用移动用户代理webhook_url
:一个用于发送最终截图对象的webhook URL(字符串
)
模板
$bb->get_template("template uid"); $bb->update_template("template uid", [ "name" => "New Template Name", "tags" => ["portrait", "instagram"], ]); // Page, Limit, Tag, Name $bb->list_templates(1, 100, 'tag', 'name');
模板集
$bb->get_template_set("template set uid"); $bb->list_template_sets(2);
视频模板
$bb->get_video_template("video template uid"); $bb->list_video_templates(2);
签名URL
此gem还包括一个方便的生成签名URL的实用程序。按照上述方式验证,然后
$bb->generate_signed_url("base uid", [ "modifications" => []]); // example $bb->generate_signed_url("A89wavQyY3Bebk3djP", [ "modifications" => [ [ "name" => "country", "text" => "testing!", ], [ "name" => "photo", "image_url" => "https://images.unsplash.com/photo-1638356435991-4c79b00ebef3?w=764&q=80", ], ], ]); // => https://ondemand.bannerbear.com/signedurl/A89wavQyY3Bebk3djP/image.jpg?modifications=W3sibmFtZSI6ImNvdW50cnkiLCJ0ZXh0IjoidGVzdGluZyEifSx7Im5hbWUiOiJwaG90byIsImltYWdlX3VybCI6Imh0dHBzOi8vaW1hZ2VzLnVuc3BsYXNoLmNvbS9waG90by0xNjM4MzU2NDM1OTkxLTRjNzliMDBlYmVmMz93PTc2NCZxPTgwIn1d&s=40e7c9d4902b86ea83e0c400e57d7cc580534fd527e234d40a0c7ace589a16eb
贡献
欢迎在GitHub上提交错误报告和拉取请求:https://github.com/yongfook/bannerbear-php。此项目旨在成为一个安全、欢迎的协作空间,并期望贡献者遵守行为准则。
许可协议
此gem在MIT许可协议下作为开源软件提供。
行为准则
期望与Bannerbear项目代码库、问题跟踪器、聊天室和邮件列表互动的每个人都遵守行为准则。