I'm struggling with a problem that I need Sonata Media Bundle to upload pictures to different folders. What I'm trying to reach is to generate a picture structure as the following: if the picture has an ID for 1234567 the original image will be put into folder: "/web/uploads/1234/567/original' And all the generated thumbnails/sizes will be like: "/web/uploads/1234/567/100x130" and "/web/uploads/1234/567/200x100" depending on the generated size.
Is this folder structure generation possible in Sonata Media Bundle and if yes, how?
Thanks for the answers. Jozef
We worked out a "workaround" for this problem:
Basically what we have done is that we created our own Generator, Provider and Resizer to match our needs and than injected it back to the Media Bundle. The generator implements Generator Interface, the constructor only has one argument ($this->firstLevel = 1000;). Than:
This will create the sub directories in the preferred way "/web/uploads/1234/567" for image with ID "1234567".
Our provider extends ImageProvider and has only 1 instances:
Our Resizer class will extend squareResizer. This was changed to be able to generate pictures (thumbnails) the exact size (100x100 and 190x100 also) by cropping the image. For this we created a new resizer which implements ResizerInterface:
It was a bit challenge to do the dependency injection, but here is the result:
Services:
Configuration:
and Extension:
And finally the config.yml from the symfony config file:
I know this is not the clearest work, but it does the job, good for now :)