This bundle integrates Imagify PHP in the Symfony framework.
Use Composer to install the bundle:
composer require ybert/imagify-bundle
Then, update your app/config/AppKernel.php
file:
public function registerBundles()
{
$bundles = array(
// ...
new Ybert\ImagifyBundle\YbertImagifyBundle(),
// ...
);
return $bundles;
}
Configure the bundle in app/config/config.yml
:
ybert_imagify:
apiKey: %imagify_apiKey%
Finally, update your app/config/parameters.yml
file to store your Imagify API credentials:
parameters:
# ...
imagify_apiKey: MyAPIKey
The bundle automatically registers a ybert_imagify.optimizer
service in the Dependency Injection Container. That service is
an instance of Imagify\Optimizer
.
Example usage in a controller:
// ...
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);
}
// ...
}