I have a beginners question.. I've built a custom module. I want to use Imagick for image manipulation from within the controller.

Imagick is properly installed on my server and works like charm from a normal .php file.

In my Controller I have

namespace <vendor>\<moduleName>\Controller\Index;

When trying to use Imagick

$image = new Imagick($imageFname);

I get an error:

Fatal error: Uncaught Error: Class '\\Controller\Index\Imagick' not found.

Obviously it looks for Imagick in the wrong place because of the namespace, but I don't know how to solve it.

Any ideas?


You need to add a backslash before the classname. In your case, it looks in the wrong location because of the namespace.


$image = new \Imagick($imageFname);

Example from Magento 2 core file: https://github.com/magento/magento2/blob/develop/lib/internal/Magento/Framework/Image/Adapter/ImageMagick.php#L251


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.