Craft v2.6.x

I want to write a plugin to grab thumbnails of PDFs.

I have my stand alone php code with imagemagick on server working like this:

$im = new Imagick();
$pdf = 'assets/documents/resources/after-release-impact-seafarers.pdf';

$im->readimage($pdf . '[0]');
//$im->resizeImage( 640, 905, imagick::FILTER_POINT, 1 );
//$im->resizeImage( 400, 565, imagick::FILTER_POINT, 1 );
$im->resizeImage( 180, 232, imagick::FILTER_POINT, 1 );


However, how can I load imagemagick - which works on the server in my PDF thumbnail plugin class function? I have tried:

    $im = new \Imagick();

    $im->readimage($pdfAsset . '[0]');
    $im->resizeImage( 640, 905, imagick::FILTER_POINT, 1 );
    $im->writeImage($pdfAsset->writepath.$pdfAsset->filename . '.jpg');

But none of the functions for imagemagick work: Eg. error i get is Class 'Craft\imagick' not found

Is this a namespace issue with the imagine library? (I sound like I know what I am talking about but I am not sure I do!)

How to include/ use native imagemagick on server in Craft?

1 Answer 1


If you want to work with PECL imagick, which is the PHP wrapper for the ImageMagick library, then this should work:

$im = new \Imagick();

It's not namespaced, so it exists in the global namespace, which is what the \ does for you.

  • Thx Brad.I load the library but the functions don't work. I get a craft namespace error : Class 'Craft\Imagick' not found on $im->resizeImage( 640, 905, Imagick::FILTER_LANCZOS, 1 ); [ or 'imagick::FILTER' etc]
    – joomkit
    Jan 4, 2018 at 22:53
  • OK i needed the back slash on the filter too! Eg $im->resizeImage( 640, 905, \Imagick::FILTER_LANCZOS, 1 )
    – joomkit
    Jan 4, 2018 at 23:14
  • Ahh, correct. Probably should have mentioned that. :)
    – Brad Bell
    Jan 4, 2018 at 23:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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