ImageMagick installation MediaTemple GridServer
Asked Answered
K

1

9

I've activated the ImageMagick extension as per the KnowledgeBase article

Basically, adding this line to php.ini:

open_basedir = /nfs:/tmp:/usr/local:/etc/apache2/gs-bin:/usr/bin/convert

However, this doesn't seem to work.
This script outputs the version number just fine:

$IM_version=shell_exec("/usr/bin/convert -version");
echo $IM_version;

However, when I try to use the Imagick class I get an error.

try
{
        /*** a new imagick object ***/
        $im = new Imagick();

        /*** Create a red rectangle  ***/
        $im->newImage( 200, 100, "red", "png" );

        /*** write image to disk ***/
        $im->writeImage( '/tmp/rectangle.png' );

        echo 'Image Created';
}
catch(Exception $e)
{
        echo $e->getMessage();
}


Error:

Fatal error: Class 'Imagick' not found in /xxxxxxxxxxxxxxx/html/mt.php on line 8

Any ideas what I'm doing wrong or what the next step for troubleshooting is?

I've contacted MediaTemple support and they just said "sorry but because the script outputs the version number it proves it's installed"

Kreit answered 29/8, 2013 at 19:37 Comment(1)
That KB article enables you to call the ImageMagick cli tools from PHP scripts, but it does not install the Imagick PEAR class (php.net/manual/en/book.imagick.php). I'm not seeing a simple way to use Imagick() on the (gs). It may need to be compiled from source and the extension stored locally in your path. I'll give that a shot.Dulcet
D
20

Ok, I got this working but it was a bit tricky. Here goes...

First, you'll want to install ImageMagick from source. This step may be optional if you already have access to 'MagickWand-config', but it wasn't in my path. Here were the steps I followed to install it into an alternate directory on the (gs):

Note: As of this post, the latest release was 6.8.9.3.

$ wget http://www.imagemagick.org/download/ImageMagick-6.8.9-3.tar.gz
$ tar xvfz ImageMagick-6.8.9-3.tar.gz
$ cd ImageMagick-6.8.9-3
$ mkdir /home/#####/etc/imagemagick
$ ./configure --prefix=/home/#####/etc/imagemagick
$ make
$ make install

The Imagick PHP class is a PECL extension so we will install it using the provided KB from Media Temple with one change. Here are the steps:

$ export SITEID=`pwd | awk -F\/ '{ print $3 }'`
$ export PHPPATH=`php-stable -i | grep "Configure Command" | perl -pe "s/.*'.\/configure'\s*?'--prefix\=(.*?)'.*/\1/"`
$ mkdir /home/$SITEID/data/lib
$ mkdir /home/$SITEID/data/lib/php/
$ wget http://pecl.php.net/get/imagick && tar zxvf imagick && cd imagick-* && $PHPPATH/bin/phpize

This is where our script deviates from the instructions. We need to specify the path to our ImageMagick install to use 'MagickWand-config'. If this isn't specified, you'll see the following error:

checking ImageMagick MagickWand API configuration program... configure: error: not found. Please provide a path to MagickWand-config or Wand-config program.

If you've used an alternate location for the source install of ImageMagick, replace the path for '--with-imagick' with that path.

$ ./configure --with-php-config=$PHPPATH/bin/php-config --with-imagick=/home/#####/etc/imagemagick

Resuming the normal instructions:

$ make && cp modules/*.so /home/$SITEID/data/lib/php

Update your php.ini file, which should be located at /home/#####/etc/php.ini and add these 2 lines:

extension_dir=/home/#####/data/lib/php/

extension = imagick.so

Once complete, here is the script I ran:

<?php

$IM_version=shell_exec("/usr/bin/convert -version");
echo $IM_version;

if (!extension_loaded('imagick'))
{
    echo "imagick not installed\n";
}
else
{
    echo "imagick installed\n";
}


try
{
        /*** a new imagick object ***/
        $im = new Imagick();

        /*** Create a red rectangle  ***/
        $im->newImage( 200, 100, "red", "png" );

        /*** write image to disk ***/
        $im->writeImage( '/tmp/rectangle.png' );

        echo 'Image Created';
}
catch(Exception $e)
{
        echo $e->getMessage();
}

Output:

Version: ImageMagick 6.6.0-4 2012-05-03 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC
Features: OpenMP 

imagick installed
Image Created
Dulcet answered 11/10, 2013 at 2:57 Comment(6)
I followed these instructions with the current version, ImageMagick-6.9.1-0.tar.gz , and it works perfectly. YOU GUYS ARE THE BEST.Gest
These instructions worked perfectly! With one little note: If your PHP version is not stable but latest, you have to replace the line that says php-stable with this one: $ export PHPPATH=php-latest -i | grep "Configure Command" | perl -pe "s/.*'.\/configure'\s*?'--prefix\=(.*?)'.*/\1/"Antenatal
This is great. I made it through the above okay, but still seem to be having some issues. When I grab the IM version, it comes back with the one MT GS has installed by default (6.7.7-10) rather than the one I installed (7.x). Any ideas as to why his would be? Now when I try image transforms they're just hanging :/Topi
@Topi Did you update your php.ini? Are you doing this via php or cli?Dulcet
These instructions still work beautifully! Thank you Chris & Rich. ImageMagick is now at version 7. If you still want to use version 6, you may need to adjust the download URL to legacy.imagemagick.org. For example: $ wget http://legacy.imagemagick.org/download/ImageMagick-6.9.11-10.tar.gzHakluyt
@Hakluyt Glad to hear!Dulcet

© 2022 - 2024 — McMap. All rights reserved.