picsmize/picsmize-php

Picsmize - 图像优化器

v1.0 2022-07-19 12:50 UTC

This package is auto-updated.

Last update: 2024-09-20 10:32:48 UTC


README

快速安装

要安装Picsmize库,以下是使用命令行安装的方法:

$ composer require picsmize/picsmize-php

配置

将Picsmize库加载到您的页面

require_once 'Picsmize/Picsmize.php';

如果您还没有API密钥,可以注册一个免费账户。就这么简单!开始优化吧..!

快速示例

这个Picsmize PHP库允许使用Picsmize API的所有操作。以下示例使用图像fetchcompressresizefilter以及不同的模式,并通过toJSON()方法直接获取输出文件。

/**
* Initialize `Picsmize` Class
*/

$picsmize = new Picsmize('your-api-key');

/**
* Use of fetch() method
*/

$picsmize->fetch('https://www.website.com/image.jpg')

/**
* Use of compress() method with medium mode
*/

->compress(Picsmize::COMPRESS_LOW)

/**
* Use of resize() method with auto mode
* and width set to 400
*/

->resize(Picsmize::RESIZE_AUTO, array(
'width' => 400
))

/**
* Use of filter() blur method with gaussian mode
* and value set to 10
*/

->filter(Picsmize::FILTER_BLUR, array(
'mode' => 'gaussian',
'value' => 10
))

/**
* Call toJSON() on the final step and return the JSON response
*/

->toJSON(function ($response) {
/**
* You'll find the full JSON metadata array within the `$response` variable.
* Remember to always check if the `status` property is set to `true`.
*/

if ($response['status'] == false) {
throw new Exception($response['message']);
}

print_r($response);
});