Is there a general class that deals with image processing (mainly resizing) that just receives a path to an image, some parameters and processes and saves the image somewhere and returns the new path?
I need this to make it work for images related to my custom entities Something like the image helper for products Magento\Catalog\Helper\Image but this looks very complicated to replicate as it's tightly coupled to the product entity.

If such a class exists in the core, I would appreciate and example on how to use.


You can try this factory class


For example if you initialize this class in your constructor you can use the below functionality.

public function __construct(                 
    \Magento\Framework\Image\AdapterFactory $imageFactory         
) {                      
    $this->imageFactory = $imageFactory;         

public function functionName($absolutePath)
   $imageProcessor = $this->imageFactory->create();         
   $imageProcessor->resize(100, 100);

   // And maybe here return the $this->destination property?
   return $this->destination;

For more functionality you can take a look in this class


I would personally wrap this whole logic in a try catch block.

  • Thanks. I'll give it a try – Marius Apr 7 '20 at 14:22

I assume you are looking for \Magento\Framework\Image

  • I might. Do you also have an example on how to use? – Marius Apr 7 '20 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.