acetonesoft/acetone-api-php
最新稳定版本:v1.0.0b
Composer 安装命令:
composer require acetonesoft/acetone-api-php
包简介
PHP class for API of AceTone.AI - remove background form your images
README 文档
README
You can programmatically remove backgrounds from your images using the API of AceTone.ai. Also you can fill background by solid color, by gradient or radial gradient. Or you can replace background by other image.
IMPORTANT: You need register an account and obtain your API key on the https://acetone.ai/
Installation
Install via composer
composer require avadim/acetone-api-php
Quick Start
use avadim\Acetone\AcetoneApi; $acetone = new AcetoneApi($apiKey); $acetone->fromFile($sourceImageFile)->save($targetImageFile);
Advanced Usage
Sources
The image can be obtained from a link, from a file, from a binary string, or from a base64-string
// Get source image from URL $acetone->fromUrl($imageUrl)->save($outFile); // Get source image from file $acetone->fromFile($imageFile)->save($outFile); // Get image from binary string $acetone->fromString($imageString)->save($outFile); // Get image as a base64-string $acetone->fromBase64($base64)->save($outFile);
Manipulations With Background
// Just remove background $acetone->fromFile($imageUrl)->bgRemove()->save($outFile); // Set background color $acetone->fromFile($imageUrl)->bgColor('f00')->save($outFile); $acetone->fromFile($imageUrl)->bgColor('#f00')->save($outFile); $acetone->fromFile($imageUrl)->bgColor([255,0,0])->save($outFile); // Fill background by a linear gradient $colors = ['f00', '33c']; $vector = -30; $acetone->fromFile($imageUrl)->bgRadialGradient($colors, $vector)->save($outFile); // Fill background by a radial gradient $colors = ['f00', '33c']; $center = [120, 240]; $acetone->fromFile($imageUrl)->bgGradient($colors, $center)->save($outFile); // Set grayscale mode of background $acetone->fromFile($imageUrl)->bgGrayscale()->save($outFile); // Set background image from binary string $bgImageFile = 'path/to/new/background'; $bgImage = file_get_contents($bgImageFile); $acetone->fromFile($imageUrl)->bgImage($bgImage)->save($outFile); // Or set background image from file $bgImageFile = 'path/to/new/background'; $acetone->fromFile($imageUrl)->bgImageFile($bgImage)->save($outFile);
Resize Result Image
$acetone->fromFile($imageFile) ->size(800, 600, AcetoneApi::IMG_FIT_COVER, AcetoneApi::IMG_FIT_COVER) ->bgImageFile($imageFileBg) ->save($outFile);
Crop Result Image to Foreground Fit
$acetone->fromFile($imageFile) ->crop() ->get();
Get Result Image as a Binary String
// You can define output format - png, jpg or webp (png is default) $imageStr = $acetone->fromFile($imageFile)->get('webp'); $image = imagecreatefromstring($imageStr); // Some manipulations imagejpeg($im, 'image.jpg');
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-07-30
