Image management
LiipImagineBundle (frontend)
The media library module uses the Liip Imagine Bundle to serve the images.
Default image filters
- The media library in fork comes with 5 predefined filters. The 5 predefined filters can be found in
app/config/config.yml
, view config.yml here. Each filter starts with anauto_rotate
andstrip
filter to ensure that uploaded images are rotated correctly (based on EXIF metadata) and stripped from that EXIF metadata as that data can contain sensitive information.
Custom image filters
- If you want to add your own filters you can easily append them yourself to the config. For more information about how to configure filters you can check the official Liip Imagine Bundle documentation.
Cropper (backend)
When you upload an image with the media library you get the option to crop or rotate the image. But in some cases you might want that crop to have a specific aspect ratio.
To set a fixed aspect ratio you need to use the option aspect_ratio
of the MediaGroupType (Backend\Modules\MediaLibrary\Domain\MediaGroup\MediaGroupType
). This option accepts an AspectRatio (Backend\Modules\MediaLibrary\Domain\MediaItem\AspectRatio
).
The height and width of the final image will depend match the height and width of the cropped area of the original image to prevent stretching or compressing.
class MyFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add(
'mediaGroup',
\Backend\Modules\MediaLibrary\Domain\MediaGroup\MediaGroupType::class,
[
'label' => 'lbl.MediaConnected',
'constraints' => [new \Symfony\Component\Validator\Constraints\Valid()],
'required' => false,
'aspect_ratio' => \Backend\Modules\MediaLibrary\Domain\MediaItem\AspectRatio::fromWidthAndHeight(16, 9)
]
);
}
}