skip to Main Content

I need to use imagick PHP extension for image manipulation. Before I installed this extension, I also installed ImageMagick on the machine using sudo apt install imagemagick. Turns out, this version is outdated (because it’s not supporting HEIC image format). So I installed ImageMagick from the source, which installed as magick package. But the PHP’s imagick extension is still working with earlier outdated imagemagick.

How do I tell PHP’s imagick extension to use the latest magick package I installed from source?

2

Answers


  1. If you’re using distro’s own PHP imagick module, it will be impossible to use your own ImageMagick copy.

    There are 2 ways to use your own ImageMagick:

    1. Compile your own PHP from source with the specified ImageMagick copy.
    2. Use ImageMagick with command line through proc_open or similar function calls.

    I guess the second option would be much easier and more flexible than to compile the whole PHP. It’s best to keep using distro’s PHP, with all the security updates and patches delivered to you automatically, than to maintain your own binary.

    Login or Signup to reply.
  2. To build the imagick PECL extension from source based on a non-standard ImageMagick installation directory you need to specify the directory using the --with-imagick argument of the extension’s configure script.

    However, the pecl command provides more user-friendly way to install PECL extensions. Here is how you can install both the ImageMagick package and the imagick PECL extension:

    1. Install ImageMagick:
    # Prepare target directory.
    # !!!
    # !!! Warning: Replace this path with whatever path you prefer on your system.
    # !!!
    target_dir="/home/johndoe/usr/lib/imagemagick"
    
    mkdir -p "$target_dir"
    
    git clone https://github.com/ImageMagick/ImageMagick.git ImageMagick-7.1.1
    cd ImageMagick-7.1.1
    ./configure --prefix="$target_dir"
    make
    make install
    
    1. Install the PECL extension:
    sudo pecl install imagick
    

    The command will ask to provide a path to the ImageMagick installation directory. Paste the ImageMagick installation directory here (replace /home/johndoe/usr/lib/imagemagick with your path):

    Please provide the prefix of ImageMagick installation [autodetect] : /home/johndoe/usr/lib/imagemagick
    

    Then add extension=imagick.so to php.ini or run PHP CLI with -d 'extension=imagick.so' arguments, e.g.:

    $ php -d 'extension=imagick.so' -m | grep imagick
    imagick
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search