imagify-bundle
This bundle integrates Imagify PHP in the Symfony framework., (*1)
Installation
Use Composer to install the bundle:, (*2)
composer require ybert/imagify-bundle
, (*3)
Then, update your app/config/AppKernel.php
file:, (*4)
public function registerBundles()
{
$bundles = array(
// ...
new Ybert\ImagifyBundle\YbertImagifyBundle(),
// ...
);
return $bundles;
}
Configure the bundle in app/config/config.yml
:, (*5)
ybert_imagify:
apiKey: %imagify_apiKey%
Finally, update your app/config/parameters.yml
file to store your Imagify API credentials:, (*6)
parameters:
# ...
imagify_apiKey: MyAPIKey
Usage
The bundle automatically registers a ybert_imagify.optimizer
service in the Dependency Injection Container. That service is
an instance of Imagify\Optimizer
., (*7)
Example usage in a controller:, (*8)
// ...
public function optimizeImage()
{
/**
* Get the Imagify service
*
* @var \Imagify\Optimizer $imagify
*/
$imagify = $this->get('ybert_imagify.optimizer');
$param = array(
"level"=> 'ultra',
"resize"=> array("width"=> 50),
);
$image = '1.jpg';
$result = $imagify->optimize($image, $param);
}
// ...
}