PHP code example of acetonesoft / acetone-api-php

1. Go to this page and download the library: Download acetonesoft/acetone-api-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

acetonesoft / acetone-api-php example snippets


use avadim\Acetone\AcetoneApi;

$acetone = new AcetoneApi($apiKey);
$acetone->fromFile($sourceImageFile)->save($targetImageFile);


// 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);


// 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);


$acetone->fromFile($imageFile)
    ->size(800, 600, AcetoneApi::IMG_FIT_COVER, AcetoneApi::IMG_FIT_COVER)
    ->bgImageFile($imageFileBg)
    ->save($outFile);

$acetone->fromFile($imageFile)
    ->crop()
    ->get();

// 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');

composer