A very simple and composable image server for Symfony applications.
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require audience-hero/image-server-bundle "~1"
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php
file of your project:
<?php
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new AudienceHero\Bundle\ImageServerBundle\AudienceHeroImageServerBundle(),
);
// ...
}
// ...
}
Add this to your app/config/config.yml
file:
# ...
audience_hero_image_server:
# (Optional) The doctrine cache provider key (See DoctrineCacheBundle documentation)
# cache: image_server
# ...
Add this to your app/config/routing.yml
file:
_audience_hero_image_server:
resource: "@AudienceHeroImageServerBundle/Resources/config/routing.yml"
prefix: /img
# ...
The image server responds to an endpoint and serves images with the possibility to transform them (ie: scale/crop).
{{ img('http://www.example.com/image.jpg', {'size': 400x400, 'crop': 'square-center'}) }}
$this->generateUrl('audience_hero_img_show', [
'url' => 'http://www.example.com/image.jpg',
'size' => '400x400',
'crop' => 'square-center'
]);
Possibles values for the crop
parameter:
none
Do not crop imagesquare
Crop the image to a squaresquare-center
Crop the image to a square, but centered
Possibles values for the size
parameter:
640x480
Resize the image to 640x480640x0
Resize the image to a width of 640 pixels. Height is automatically adjusted to preserve the original aspect ratio.0x480
Resize the image to a height of 480 pixels. Width is automatically adjusted to preserve the original aspect ratio.
See the LICENSE file.