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?

+3


source to share


2 answers


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.

+1


source


Test the variables with a dump (var) in a twig. Perhaps $ extn [0] does not have the correct file or is not installed. Try poutputting the full getBrowserPath line to make sure it is correct.



0


source







All Articles