Install Image::Magick with cpanm on user Perl

How to install Image::Magic with cpanm in user Perl.

First of all, the Image::Magick module is a very difficult module to install in Perl in your environment with cpanm. It is not easy to install with cpanm and you have to manually rewrite Makefile.PL.

When performing image processing in a new Perl system development, an image editing module called Imager written in Perl. There is, so let's try this first.

Install ImageMagic and execute the convert command etc. system function is the next best thing to do.

Packages required to install Image::Magick with cpanm on user Perl

Install libmagickcore-dev

Install ImageMagick headers and libraries as a prerequisite to installing Perl's Image::Magick.

Look for the following headers in ImageMagick.

find / usr / include | grep'ImageMagick.h'
find / usr / include | grep'magick-baseconfig.h'

It will be displayed as follows. The version number may be different.

/usr/include/ImageMagick-6/magick/ImageMagick.h
/usr/include/x86_64-linux-gnu/ImageMagick-6/magick/magick-baseconfig.h

Remember these ImageMagic include directories. These names may vary depending on your version of Ubuntu.

/ usr / include / ImageMagick-6
/ usr / include / x86_64-linux-gnu / ImageMagick-6

Install libperl-dev

Requires Perl headers and libraries.

Install Image::Magick with cpanm on user Perl

First, let's install Image::Magick with cpanm.

cpanm Image::Magick

It will fail. Looking at the log, it is said that "magick / magick-baseconfig.h" does not exist.

/usr/include/ImageMagick-6/magick/magick-config.h:21:10: fatal error: magick/magick-baseconfig.h: No such file or directory
 #include "magick / magick-baseconfig.h"

Rewrite Makefile to include directory "/ usr / include / ImageMagick-6".

First, change to the cpanm build directory.

cd ~ / .cpanm / latest-build

Use the ls command to display the directory.

ls

Image::Magick is included in PerlMagick, so find the following directory. The version number depends on your environment.

PerlMagick-6.89

Move to the directory.

cd PerlMagick-6.89

Edit the Makefile.

vi Makefile.PL

Rewrite $INC_magick. Add the following include directories to the beginning. "-I" is a gcc option to add an include directory.

/ usr / include / ImageMagick-6
/ usr / include / x86_64-linux-gnu / ImageMagick-6
# Change before
my $INC_magick ='-I / usr / local / include / ImageMagick-6 -DMAGICKCORE_HDRI_ENABLE = 0 -DMAGICKCORE_QUANTUM_DEPTH = 16 -I / usr / include / libxml2 -I"'. $Config {'usrinc'}.'/ ImageMagick- 6 "';

# After change
my $INC_magick ='-I / usr / include / ImageMagick-6 -I / usr / include / x86_64-linux-gnu / ImageMagick-6 -I / usr / local / include / ImageMagick-6 -DMAGICKCORE_HDRI_ENABLE = 0 -DMAGICKCORE_QUANTUM_DEPTH = 16 -I / usr / include / libxml2 -I "'. $Config {'usrinc'}.'/ ImageMagick-6"';

The rest is compilation and installation.

perl Makefile.PL
make
make install

Load the module and make sure there are no errors.

perl -e'use Image::Magick'

Associated Information