picsmize/picsmize-codeigniter

Picsmize - 图片优化器

v1.0 2022-07-19 13:04 UTC

This package is auto-updated.

Last update: 2024-09-20 11:34:57 UTC


README

快速安装

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

$ composer require picsmize/picsmize-codeigniter

配置

将Picsmize库移动到项目的库文件夹/application/third_party:要将Picsmize库加载到您的项目中,请打开/application/config/config.php并找到以下行:

$config['composer_autoload'] = FALSE;

将其替换为以下行

$config['composer_autoload'] = APPPATH . 'third_party/vendor/autoload.php';

在您的项目控制器文件中初始化库。

$picsmize = new Picsmize();

最后一步是提供您的Picsmize API密钥。在加载库之后设置。

$picsmize->setApiKey('your-api-key');

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

快速示例

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

$picsmize = new Picsmize();
$picsmize->setApiKey('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);
});