niccolox / optidash-php
Optidash的官方PHP集成 - 人工智能驱动的图像优化和处理API。我们将大幅提高您网站的加载速度,并节省带宽和存储成本。
dev-master
2022-08-11 20:41 UTC
Requires
- php: >=5.3.0
- ext-curl: *
- ext-json: *
- lib-curl: >=7.20.0
This package is auto-updated.
Last update: 2024-09-12 01:14:57 UTC
README
Optidash是一个现代的、人工智能驱动的图像优化和处理API。
我们将大幅提高您网站的加载速度,并节省您在带宽和存储上的成本。
文档
安装
$ composer require optidash/optidash
快速示例
Optidash API允许您以两种方式提供您的图像进行处理 - 直接上传到API(图像上传)或提供公开可用的图像URL(图像抓取)。
您还可以根据每个请求选择您首选的响应方法。默认情况下,Optidash API将返回一个包含有关输入和输出图像的丰富元数据的JSON响应。或者,您可以使用二进制响应。启用时,API将返回最终(输出)图像的完整二进制表示。此PHP集成提供了两个方便的方法来与二进制响应交互:toFile()和toBuffer()。
图像上传
以下是一个上传本地文件进行优化和处理的快速示例。它最终调用toJSON()并指示API返回一个JSON响应。
<?php // Pass your Optidash API Key to the constructor $opti = new Optidash\Optidash('your-api-key'); // Upload an image from disk, resize it to 100 x 75, // automatically enhance, and adjust sharpness parameter. $opti ->upload('path/to/input.jpg') ->optimize(array( 'compression' => 'medium' )) ->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 Optidash API Key to the constructor $opti = new Optidash\Optidash('your-api-key'); // Provide a publicly available image URL with `fetch()` method, // apply Gaussian blur using highly optimized PNG as the output format. // We'll also use `toFile()` method and stream the output image to disk $opti ->fetch('https://www.website.com/image.jpg') ->optimize(array( 'compression' => 'medium' )) ->filter(array( 'blur' => array( 'mode' => 'gaussian', 'value' => 10 ) )) ->output(array( 'format' => 'png' )) ->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文件。