Image::Magick and PerlBrew

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
johnfl68
Posts: 33
Joined: 2012-07-09T18:31:26-07:00
Authentication code: 13

Image::Magick and PerlBrew

Post by johnfl68 »

Anyone have any luck getting Image::Magick to work with PerlBrew?

I need to move to a larger host, thought I had found a great one, only to find out that they are using a version of Perl that is over 6 years old, and they don't want to install anything newer on the server.

With PerlBrew, I am able to install Perl and CPAN modules without having root access, etc. Works great, but when I try and install the Image::Magick module, it keeps failing.

I am hoping maybe someone here has done this, and may know what the issue is.

Thanks!

John
jkortegard
Posts: 3
Joined: 2013-11-29T14:52:06-07:00
Authentication code: 6789

Re: Image::Magick and PerlBrew

Post by jkortegard »

I've had success on OS X with perlbrew + Image::Magick + homebrew. Here's how:

1. First install your perls with perlbrew. Instructions at http://perlbrew.pl. I did the easy copy/paste into the terminal.

2. Next install homebrew. Instructions at http://brew.sh. Again, easy copy/paste into the terminal.

3. Then install imagemagick dependencies. I think homebrew would resolve deps for you, but for some reason I like to do it manually. Holdover from the olden days of manually compiling and installing ImageMagick from source, maybe. :)

Code: Select all

brew deps --1 imagemagick | xargs brew install
If you delete the "| xargs..." from the command above, it just shows you the basic imagemagick dependencies. With the pipe-xargs, homebrew does the installation of those dependencies. If you spend much time on the command line and aren't familiar with "xargs", it's worth studying.

4. Enter "brew edit imagemagick" in the terminal to modify the default homebrew formula for imagemagick. This will open up a file "imagemagick.rb" in a text editor (probably vi or vim in your terminal). Navigate to around line 60, where the installation args are specified, and make a couple changes. In the "git diff" output below you can see the 2 lines I added marked with "+" on the left margin. The perl path on the right is just the output of "which perl" from the command line. The other addition is to support Ghostscript for vector image processing.

Code: Select all

diff --git i/Library/Formula/imagemagick.rb w/Library/Formula/imagemagick.rb
index 22f0164..e29fd64 100644
--- i/Library/Formula/imagemagick.rb
+++ w/Library/Formula/imagemagick.rb
@@ -60,6 +60,8 @@ class Imagemagick < Formula
   def install
     args = [ "--disable-osx-universal-binary",
              "--prefix=#{prefix}",
+             "--with-perl=/Users/jkortegard/perl5/perlbrew/perls/perl-5.18.1/bin/perl",
+             "--with-gslib",
              "--disable-dependency-tracking",
              "--enable-shared",
              "--disable-static",
(END)
5. Save your changes to the "imagemagick.rb" file and install ImageMagick using homebrew. Mine are shown below. NOTE: you need to include the "--with-perl" option on the command line for homebrew to build and install PerlMagick correctly as part of the ImageMagick installation. The "-vd" options give you verbose debug output to screen while installing. If you're used to building ImageMagick, it will look familiar.

Code: Select all

$ brew install -vd --fresh imagemagick --with-fontconfig --with-freetype --with-webp --with-ghostscript --with-jasper --with-librsvg --with-libtiff --with-little-cms --with-quantum-depth-8 --with-perl
6. Confirm you have a working PerlMagick.

Code: Select all

$ perl -wle 'use Image::Magick; print Image::Magick->new->Get("version"); print "perl version " , $];'
ImageMagick 6.8.7-7 Q8 x86_64 2013-11-29 http://www.imagemagick.org
perl version 5.018001
If you want to have multiple PerlMagick installs, for each of your perlbrew versions, you can do that too. I have it built for 5.16 and 5.18 currently. It might be a total hack, but it seems to work. Here's what I did:

1. Everything above for a given Perl version.
2. "brew rm imagemagick" -- Delete the installed ImageMagick. This does NOT remove any of the PerlMagick installation.
3. "perlbrew switch perl-5.16.3"
4. Repeat the "brew edit" step above to update the perl path in the imagemagick.rb file to the freshly activated perlbrew version.
5. Repeat the "brew install" step above verbatim.

Now I can switch Perls and Image::Magick plays along nicely:

Code: Select all

$ perlbrew list
  perl-5.16.3
* perl-5.18.1
$ perl -wle 'use Image::Magick; print Image::Magick->new->Get("version"); print "perl version " , $];'
ImageMagick 6.8.7-7 Q8 x86_64 2013-11-29 http://www.imagemagick.org
perl version 5.018001
$ perlbrew switch perl-5.16.3
$ perl -wle 'use Image::Magick; print Image::Magick->new->Get("version"); print "perl version " , $];'
ImageMagick 6.8.7-7 Q8 x86_64 2013-11-29 http://www.imagemagick.org
perl version 5.016003
$
Caveat: I have not done rigorous testing of every aspect of PerlMagick after these installations. It works as far as I can tell, though.

Jamin
sillymoose
Posts: 1
Joined: 2014-01-08T09:18:45-07:00
Authentication code: 6789

Re: Image::Magick and PerlBrew

Post by sillymoose »

Hey,

I wrote an article on PerlTricks.com that describes how solve this issue, there is even a Bash script to do it for you. http://perltricks.com/article/57/2014/1 ... in-minutes


Thanks,

David
jeteve
Posts: 2
Joined: 2014-05-02T10:09:28-07:00
Authentication code: 6789

Re: Image::Magick and PerlBrew

Post by jeteve »

Hi there,

I've made a perlbrew + cpanm compatible perl package.

Please note that your perl should be compiled with -Duseshrplib:

Code: Select all

perlbrew --force install <your version> -D useshrplib
Then it should be as simple as:

Code: Select all

cpanm Alien::ImageMagick
More info here: https://metacpan.org/release/Alien-ImageMagick

Cheers,

Jerome.
Post Reply