placidapp / placid-php
Placid.app REST API 的 PHP 封装
v1.0.1
2022-07-20 17:49 UTC
Requires
- php: ^7.4|^8.0
- ext-curl: *
- ext-json: *
This package is auto-updated.
Last update: 2024-09-20 22:58:36 UTC
README
PHP 版本 Placid
此包允许您自动从 Placid 模板创建图像。您可以使用 REST API 或 URL API 创建带有变量以动态设置图像内容的 placid.app 嵌入链接。
关于 Placid
要使用此包,您需要一个 Placid 账户,在那里您可以添加、设计和编辑图像模板。
这是一种自动为您的内容创建分享图像的服务:Open Graph 图像(og:images)、Twitter 卡图像和 Pinterest 图像。这可以节省您数小时的时间,以便在发布后使您的内容可分享。我们还提供了一些现成的精美预设设计,您可以直接使用。
不仅仅只有分享图像:使用我们的编辑器,您可以完全控制您的模板,因此您还可以将其用于其他类型的图像,以添加到您的内容中(如预告或博客图形)。
安装
您可以使用以下命令通过 composer 安装此包
composer require placidapp/placid-php
创建 placid.app 图像 URL
use Placid\Template; $templateId = "qsraj"; $apiKey = "your-placid-api-key"; $template = new Template($templateId, $apiKey) $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。
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件。