Symfony2 Sonata Media Bundle Custom Image Cropping

3.5k views Asked by At

It seems that Sonata Media has only two strategies when it comes to cropping/resizing the uploaded image, Sonata\MediaBundle\Resizer\SimpleResizer and Sonata\MediaBundle\Resizer\SquareResizer. Both these strategies are automatic, meaning that the users don't have a say in how they want the image to be resized/croppped.

I would like to give the user an option to select the portion of the image that is more relevant, kind like the jQuery Image Cropper library used by GenemuFormBundle, but I don't even know where to start. Will I need to create my own Admin class instead of using Sonata\MediaBundle\Admin\BaseMediaAdmin? Has anyone write a bundle that I can use? How do you manage your galleries usually?

enter image description here

3

There are 3 answers

0
Mait' On

I wrote a simple admin extension that give you the ability to customize the images by format. It's actually a Work In Progress that needs some test, documentation and refactoring, but it does the job, it's lightweight and it's shipped with a resizer to handle fixed dimensions.

You can find it here: https://github.com/julien-maitan/sonata-media-crop

0
Can On

You should look at ComurImageBundle. It's far easier than Sonata Media, doesn't create anything in database and lets you upload with jquery file uploader, crop with jcrop and other useful things.

enter image description here

0
Sumeet On

If you are using sonata media bundle with sonata admin, there is a picasa photo editor already in place in media edit form.

Please check.