neo/smushit

为 Yahoo! Smushit 服务添加包装器。

dev-master 2013-12-21 08:01 UTC

This package is auto-updated.

Last update: 2024-09-16 17:10:12 UTC


README

Build Status

这是一个库,可以轻松地在项目中使用 Smush.it API。使用简单,首先通过解压缩到库目录或更简单地使用 composer 安装该库。

要求

  • JSON 扩展
  • cURL 扩展

安装

使用 Composer

将以下内容添加到您的 composer 文件中

"require" : {
	"neo/smushit" : "dev-master"
}

然后,您现在可以运行 composer install 命令,并让它安装所有依赖项。

用法

要对图像进行压缩,您应该这样做

$original_image = 'http://placehold.it/300x300';

try
{
    $response = Neo\Smushit\Smushit::make($original_image);

	$resized = $response->dest;
}
catch(Neo\Smushit\Exception\SmushitException $e)
{
	$resized = $original_image;
}

以下是一个示例响应,可以帮助您准确地解码如何处理各种响应

成功响应

{
	"src":"http://placehold.it/300x300",
	"src_size":1200,
	"dest":"http://ysmushit.zenfs.com/results/c1c4ef27%2Fsmush%2F300x300.png",
	"dest_size":921,
	"percent":"23.25",
	"id":""
}

失败响应

{
	"src":"http://placehold.it",
	"error":"Could not get the image",
	"id":""
}