0

In an Symfony2 controller I'm processing some images that belong to a product. When the images are added to a product the images are cropped with Imagick. This is done in the Entity of that product with the following code:

$image = new \Imagick( $imageUrl );

This works fine in the controller. But now I'm moving the code to the Symfony Command so it can be run from the command line. Only I'm getting the error that Imagick is not loaded.

[Symfony\Component\Debug\Exception\ClassNotFoundException]
Attempted to load class "Imagick" from the global namespace.
Did you forget a "use" statement?

I though because of using the / in front it was used from the global namespace. Or is the global namespace not know in the command section of Symfony?

Tom
  • 1,547
  • 7
  • 27
  • 50
  • 1
    I think the problem is that the imagick extension isn't installed. That's why the class can't be found. – Daan Meijer Jan 04 '17 at 12:39
  • But it works from the controller it only does not work from the Symfony command functions. – Tom Jan 04 '17 at 12:40
  • 2
    Well, maybe the extension is loaded in the Apache environment, but not the CLI (command line php) environment? – Daan Meijer Jan 04 '17 at 12:41
  • Daan is correct, controllers use a different PHP environment than commands and the error suggests the ImageMagick extension is not loaded in the PHP environments that commands use (php-cli). Make sure to enable it in your configuration. – Oldskool Jan 04 '17 at 12:43
  • Are there any chances that CLI is running under another instance of PHP? Try running php -i from the command line and see if imagick is listed there. – Stas Parshin Jan 04 '17 at 12:43
  • With the php -i comand I only see an path to imagemagick. $_SERVER['PATH'] => /Application/MAMP/bin/php/php7.0.8/bin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/ImageMagick/bin:/Users/tom/.rvm/bin – Tom Jan 04 '17 at 12:51
  • Instead of `php -i`, run `php -m`, that should show all the php extension that are activated. My guess is imagick doesn't show up. If it doesn't, you'll need to enable it in the relevant php.ini – Daan Meijer Jan 04 '17 at 13:03
  • Your correct, it does not show op. Do you maybe have an example on how to enable it in the php.ini file. I looked already in the php.ini file but nothing there about ImageMagick? – Tom Jan 04 '17 at 13:05
  • "extension=imagick.so" - ImageMagick is the C library, Imagick is the extension – Danack Jan 05 '17 at 01:26

0 Answers0