Skip to content

Instantly share code, notes, and snippets.

@kberov
Last active July 24, 2018 20:29
Show Gist options
  • Save kberov/d5aa1414d74f4527436ec07952c6e2a5 to your computer and use it in GitHub Desktop.
Save kberov/d5aa1414d74f4527436ec07952c6e2a5 to your computer and use it in GitHub Desktop.
To use Image::Magic with Perl, Perl must be compiled with some special CFLAGS! and ImageMagick must be compiled with this perl Example:
#!/usr/bin/env bash
# My notes - K. Berov:
# Copied from
# https://gist.githubusercontent.com/zmughal/8264712/raw/8831e421393143c5b48f22dcfa12eeda51c5cfbf/install-imagemagick-perl
# and modified for my self.
# I already have several perls
# I will use 5.26.2 for this installation
# See https://www.perl.com/article/57/2014/1/1/Shazam--Use-Image--Magick-with-Perlbrew-in-minutes/
# See mainly the following as this configuration actually worked:
# https://github.com/lecstor/DevNotes/wiki/Image-Magick-with-Perlbrew
# IMPORTANT!!: When compiling you must use a cflag -fPIC. I compiled with perlbrew like this:
# perlbrew install --notest --noman --as c3-fPIC-5.26.2 -Duselargefiles -Dcccdlflags=-fPIC -Duseshrplib perl-5.26.2
perlbrew use c3-fPIC-5.26.2
source ~/.profile
# The directory where image Magic will be installed.
TOP="$HOME/.local"
# NOTE!!! after compiling Perl, run this script from the directory where you unpacked ImageMagic.
# If run with argument cd to the directory $1 - this must be the unpacked ImageMagic
if [ -n "$1" ]; then
cd $1
fi
PERL_CORE=$(perl -e 'print grep { -d } map { "$_/CORE" } @INC')
PERL_BIN=$(which perl)
PERL_THREADS=$(perl -V | grep -c 'useithreads=define')
THREAD_FLAG="--with-threads"
if [ $PERL_THREADS = 0 ]; then
THREAD_FLAG="--without-threads"
fi
echo "LDFLAGS=-L$PERL_CORE"
echo --prefix=$TOP
echo "--with-perl=$PERL_BIN"
echo '$THREAD_FLAG:'$THREAD_FLAG
#exit
LDFLAGS=-L$PERL_CORE \
./configure --prefix=$TOP \
--with-perl=$PERL_BIN \
--with-ghostscript \
--enable-shared $THREAD_FLAG \
--disable-static
make && make install
# Test the install
#
# perl -MImage::Magick -E 'say ${"$Image::Magick::ISA[0]".::VERSION}'
#
# perl -MImage::Magick -e '$p = Image::Magick->new; $p->Read("magick:rose"); $p->Write("/tmp/test.png")'; display /tmp/test.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment