placidapp / placid-laravel
Placid.app Laravel 集成
v1.0.1
2022-07-20 18:09 UTC
Requires
- php: ^7.4|^8.0
- placidapp/placid-php: ^1.0.1
This package is auto-updated.
Last update: 2024-09-20 22:38:16 UTC
README
Placid for Laravel
此包允许您自动从 Placid 模板创建图像。您可以使用 REST API 或 URL API 创建带有变量的 placid.app 嵌入链接,以动态设置图像内容。
关于 Placid
要使用此包,您需要一个 Placid 账户,您可以在其中添加、设计和编辑图像模板。
这是一个自动为您的内容创建共享图像的服务:Open Graph 图像(og:images)、Twitter 卡图像和 Pinterest 图像。这可以在发布后节省您数小时来使您的内容可分享。我们还提供了一些精美的预设设计,您可以直接使用。
不仅仅是共享图像:使用我们的编辑器,您可以对模板拥有完全控制权,因此您还可以用它来添加其他类型的图像到您的内容中(如预告或博客图形)。
创建 placid.app 图像 URL
$templateId = "qsraj"; $template = Placid::template($templateId) $template ->elementText($title) ->text("I am a dynamic image"); $imageURL = $template->toPlacidUrl(); // - https://placid.app/u/qsraj?title=I%20am%20a%20dynamic%20Image%21
生成图像
在模板对象上使用 image()
函数将返回一个 GeneratedImage 对象。当图像创建完成后,您在配置中定义的 webhook 将被调用!
$image = $template->image();
image(true)
将等待图像完成
$image = $template->image(true); // - https://placid.app/u/qsraj?title=I%20am%20a%20dynamic%20Image%21
字段
您可以在模板中添加不同元素,这些元素可以动态更改和填充。
文本字段
$template ->elementText("text") // - Layer name in your template ->text("This is the text") ->color('#ff0022'); // - Text color as hex-code
请注意:只有在您使用 image()
函数生成图像时,才能更改文本颜色,而使用 URL API 时则不能。
图片字段
$template ->elementPicture('picture') // - Layer name in your template ->imageFromUrl( "https://madewithvuejs.com/mandant/madewithvuejs/images/logo.png" // - image source ); $template ->elementPicture('picture') // - Layer name in your template ->imageFromWebsite("https://madewithvuejs.com"); // - URL of a page to screenshot
浏览器框架字段
$template ->elementBrowserframe('browserframe') // - Layer name in your template ->imageFromUrl( "https://madewithvuejs.com/mandant/madewithvuejs/images/logo.png" // - image source ) ->url("madewithvuejs.com"); // - URL that will be displayed in the browserframe's address bar $template ->elementBrowserframe('browserframe') // - Layer name in your template ->imageFromWebsite("https://madewithvuejs.com") // - URL of a page to screenshot ->url("madewithvuejs.com"); // - URL that will be displayed in the browserframe's address bar
矩形字段
$template ->elementRectangle('rectangle') // - Layer name in your template ->backgroundColor("#000000"); // - Background color as hex-code
请注意:只有在您使用 image()
函数生成图像时,才能更改背景颜色,而使用 URL API 时则不能。
安装
您可以通过 composer 使用以下命令安装此包
composer require placidapp/placid-laravel
此包将自动注册自身。
您可以使用以下命令发布配置文件
php artisan vendor:publish --provider="Placid\Laravel\PlacidLaravelServiceProvider" --tag="config"
以下是发布配置文件的内容
return [ /** * Placid API Token */ 'api-token' => null, /** * Placid Success Webhook * * Will be called when your created image is ready */ 'webhook_url' => null ];
许可证
MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件。