title: Laravel 5.2: Class Imagick not found
body: <p>We are converting PDF pages to multiple single images. We found a code snippet in stackoverflow and converted it to a service class. We have Imagick installed and it shows up in phpinfo() as well. However, in our laravel application, version 5.2, we are getting following error.</p>
  
  <pre><code>ReflectionException in Container.php line 798:
  Class Imagick does not exist
  </code></pre>
  
  <p>We tested our code outside laravel environment and it's working like a charm. No such error is thrown. We also ran following command to check Imagick</p>
  
  <pre><code>php -i | grep -i imagick
  </code></pre>
  
  <p>and this is the output</p>
  
  <pre><code>    /etc/php5/cli/conf.d/20-imagick.ini,
      imagick
      imagick module =&gt; enabled
      imagick module version =&gt; 3.4.3RC1
      imagick classes =&gt; Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator
      Imagick compiled with ImageMagick version =&gt; ImageMagick 6.7.7-10 2016-06-01 Q16 http://www.imagemagick.org
      Imagick using ImageMagick library version =&gt; ImageMagick 6.7.7-10 2016-06-01 Q16 http://www.imagemagick.org
      imagick.locale_fix =&gt; 0 =&gt; 0
      imagick.progress_monitor =&gt; 0 =&gt; 0
      imagick.skip_version_check =&gt; 0 =&gt; 0
  </code></pre>
  
  <p>Everything seems right. It works outside Laravel but not in laravel. I got no idea what's wrong. Do we have to configure Laravel to use Imagick?</p>
  
  <p>Here is our service class that we are using</p>
  
  <pre><code>&lt;?php
  
  namespace App\Services\Utilities;
  
  use Imagick;
  
  class PdfToImageService
  {
      /**
       * Destination folder where images will be saved
       * @var string
       */
      protected $destination = 'images/users/';
  
      /**
       * Injecting dependencies
       * 
       * @param Imagick $imagick
       */
      function __construct(Imagic $imagick)
      {
          $this-&gt;imagick = $imagick;
      }
  
      /**
       * Convert pdf having multiple pages to multiple single images
       * 
       * 1. Strip document extension
       * 2. Convert this document
       * 3. Set background color and flatten. It Prevents black background on objects with transparency
       * 4. Set image resolution
       * 5. Determine number of pages
       * 6. Compress Image Quality
       * 7. Generate images from each pdf page
       * 8. Destroy current imagick session
       * 
       * @param  string $fileName
       * @return array  $convertedImageNames
       */
      public function createImages($fileName)
      {
          $fileName = basename($fileName);
          $this-&gt;imagick-&gt;readImage($fileName);
          $this-&gt;imagick-&gt;setImageBackgroundColor('white');
          $this-&gt;imagick-&gt;setResolution(300,300);
          $this-&gt;imagick-&gt;setImageCompressionQuality(100);
  
          $convertedImageNames = $this-&gt;generateImageFromPDFPage(
              $fileName, $this-&gt;imagick-&gt;getNumberImages()
          );
  
          $this-&gt;imagick-&gt;destroy();
  
          return $convertedImageNames;
      }
  
      /**
       * Loop throught each pdf pages and convert it to image.
       *      A. Set iterator postion
       *      B. Set image format
       *      C. Write Images to destination folder 
       * 
       * @param  string  $fileName
       * @param  integer $noOfPages
       * @return array
       */
      private function generateImageFromPDFPage($fileName, $noOfPages)
      {
          for($i = 0;$i &lt; $noOfPages; $i++) {
              $this-&gt;imagick-&gt;setIteratorIndex($i);
              $this-&gt;imagick-&gt;setImageFormat('jpeg');    
              $this-&gt;imagick-&gt;writeImage($this-&gt;destination.$fileName.'-'.$i.'.jpg');
              $convertedImageNames[$i] = $fileName.'-'.$i.'.jpg';
          }
  
          return $convertedImageNames;
      }
  }
  </code></pre>