Symfony2 - resize image after upload
I want to create thumbnails after uploading a file. For image manipulation I am using Avalanche123 ImagineBundle.
I tried to use the code in Entity:
$avalancheService = $this->get('imagine.cache.path.resolver');
$avalancheService->getBrowserPath($this->getUploadRootDir().'/'.$path.'/'.$extn[0].'.jpg', 'avatar');
But that doesn't help. What can I do?
source to share
In this line you are trying to get the service: $this->get('imagine.cache.path.resolver')
.
But the example code you are following needs to be executed in the controller. There is no method in the Entity get()
, the controller inherits it from the class Controller
that all controllers should propagate. Therefore, the challenge $this->get()
is essentially meaningless.
This is by design. Entities in Symfony should be dumb and only represent the data they have.
That's right, you either need to resize your controller, or create a service, inject imagine.cache.path.resolver
into it and call it from your controllers.
source to share