<p>If you want to work with <a href="https://secure.php.net/manual/en/class.imagick.php" rel="nofollow noreferrer">PECL imagick</a>, which is the PHP wrapper for the <a href="https://www.imagemagick.org/script/index.php" rel="nofollow noreferrer">ImageMagick</a> library, then this should work:</p>

<pre><code>$im = new \Imagick();
</code></pre>

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

CC BY-SA 3.0
2018-01-04T22:53:52.640Z
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
CC BY-SA 3.0
2018-01-04T23:14:16.837Z
OK i needed the back slash on the filter too! Eg $im->resizeImage( 640, 905, \Imagick::FILTER_LANCZOS, 1 )
joomkit
CC BY-SA 3.0
2018-01-04T23:15:37.963Z
Ahh, correct.  Probably should have mentioned that. :)
Brad Bell
CC BY-SA 3.0
2018-01-04T18:37:08.103Z
2018-01-04T18:37:08.103Z
Brad Bell
<p>Craft v2.6.x</p>

<p>I want to write a plugin to grab thumbnails of PDFs.</p>

<p>I have my stand alone php code with imagemagick on server working like this:</p>

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

$im-&gt;setResolution(300,300);
//$im-&gt;setCompressionQuality(95);
//$im-&gt;scaleImage(200,0);
$im-&gt;readimage($pdf . '[0]');
$im-&gt;setImageFormat('jpeg');
//$im-&gt;resizeImage( 640, 905, imagick::FILTER_POINT, 1 );
//$im-&gt;resizeImage( 400, 565, imagick::FILTER_POINT, 1 );
$im-&gt;resizeImage( 180, 232, imagick::FILTER_POINT, 1 );

$im-&gt;writeImage('1a2w12thumb.jpg');
$im-&gt;clear();
$im-&gt;destroy();
</code></pre>

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

<pre><code>    $im = new \Imagick();

    $im-&gt;setResolution(300,300);
    $im-&gt;readimage($pdfAsset . '[0]');
    $im-&gt;setImageFormat('jpeg');
    $im-&gt;resizeImage( 640, 905, imagick::FILTER_POINT, 1 );
    $im-&gt;writeImage($pdfAsset-&gt;writepath.$pdfAsset-&gt;filename . '.jpg');
    $im-&gt;clear();
    $im-&gt;destroy();
</code></pre>

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

<p>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!)</p>

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

<plugin-development><imagick>
How to include and use native imagemagick on server in Craft?
# How to include and use native imagemagick on server in Craft?

(Asked by: username_0 on 2018-01-04)

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->setResolution(300,300);
//$im->setCompressionQuality(95);
//$im->scaleImage(200,0);
$im->readimage($pdf . '[0]');
$im->setImageFormat('jpeg');
//$im->resizeImage( 640, 905, imagick::FILTER_POINT, 1 );
//$im->resizeImage( 400, 565, imagick::FILTER_POINT, 1 );
$im->resizeImage( 180, 232, imagick::FILTER_POINT, 1 );

$im->writeImage('1a2w12thumb.jpg');
$im->clear();
$im->destroy();

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->setResolution(300,300);
    $im->readimage($pdfAsset . '[0]');
    $im->setImageFormat('jpeg');
    $im->resizeImage( 640, 905, imagick::FILTER_POINT, 1 );
    $im->writeImage($pdfAsset->writepath.$pdfAsset->filename . '.jpg');
    $im->clear();
    $im->destroy();

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?

**Tags:** plugin-development, imagick

---

## 1 answers

### Answer by username_1 on 2018-01-04. Score: 0 | Accepted answer

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.

> **Comments:**
> **username_0**: 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]  
> **username_0**: OK i needed the back slash on the filter too! Eg $im->resizeImage( 640, 905, \Imagick::FILTER_LANCZOS, 1 )  
> **username_1**: Ahh, correct.  Probably should have mentioned that. :)  

---

