pixaven / pixaven-php
Pixaven Image API的官方PHP集成 - 完全运行在Apple®平台上的企业级图像处理SaaS。以闪电般的速度调整、缩放、裁剪、蒙版、过滤和增强您的图像。
1.0.2
2019-10-22 12:07 UTC
Requires
- php: >=5.3.0
- ext-curl: *
- ext-json: *
- lib-curl: >=7.20.0
This package is auto-updated.
Last update: 2024-09-22 22:32:44 UTC
README
Pixaven是一个现代化的、GPU加速的图像处理API。
我们以闪电般的速度转换、增强、调整、裁剪、风格化、过滤和添加水印到您的图像。
文档
请参阅Pixaven API文档。
安装
$ composer require pixaven/pixaven-php
快速示例
Pixaven API允许您以两种方式提供图像进行处理 - 直接上传到API(图像上传)或提供公开可用的图像URL(图像抓取)。
您还可以根据每个请求选择您首选的响应方法。默认情况下,Pixaven API将返回包含有关输入和输出图像的丰富元数据的JSON响应。或者,您可以使用二进制响应。启用时,API将以完整二进制表示形式响应结果(输出)图像。此PHP集成公开了两个方便的方法来处理二进制响应:toFile()
和toBuffer()
。
图像上传
以下是一个上传本地文件进行处理的快速示例。它最终调用toJSON()
并指示API返回JSON响应。
<?php // Pass your Pixaven API Key to the constructor $pix = new Pixaven\Pixaven('your-api-key'); // Upload an image from disk, resize it to 100 x 75, // automatically enhance, and adjust sharpness parameter. $pix ->upload('path/to/input.jpg') ->resize(array( 'width' => 100, 'height' => 75 )) ->auto(array( 'enahnce' => true )) ->adjust(array( 'unsharp' => 10 )) ->toJSON(function ($error, $meta) { if (!empty($error)) { throw new Exception($error); } // You'll find the full JSON metadata within the `meta` variable });
图像抓取
如果您已经在网络上公开了您的源视觉元素,我们建议默认使用图像抓取。这样,您只需发送包含图像URL和处理步骤的JSON有效负载。此方法也比上传图像的完整二进制表示要快得多。
<?php // Pass your Pixaven API Key to the constructor $pix = new Pixaven\Pixaven('your-api-key'); // Provide a publicly available image URL with `fetch()` method, // apply Gaussian blur using PNG as the output format. // We'll also use `toFile()` method and stream the output image to disk $pix ->fetch('https://www.website.com/image.jpg') ->filter(array( 'blur' => array( 'mode' => 'gaussian', 'value' => 10 ) )) ->output(array( 'format' => 10 )) ->toFile('path/to/output.png', function ($error, $meta) { if (!empty($error)) { throw new Exception($error); } // You'll find the full JSON metadata within the `meta` variable });
许可证
本软件根据MIT许可证分发。有关更多信息,请参阅LICENSE文件。