Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

macos - Compile ImageMagick from source with PNG support on OSX

I need to compile it from sources. I followed step by step instruction to build it with jpeg and png support but ImageMagick didn't include PNG to delegates list however jpeg has been included. What is wrong with PNG?

Options used to compile and link:
PREFIX          = /opt/im
EXEC-PREFIX     = /opt/im
VERSION         = 6.9.2
CC              = gcc
CFLAGS          =   -g -O2 -Wall -mtune=haswell -fexceptions -D_FORTIFY_SOURCE=0 -D_THREAD_SAFE -pthread -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16
CPPFLAGS        =   -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/tmp/IM/ImageMagick-6.9.2-10/jpeg -I/tmp/IM/ImageMagick-6.9.2-10/magick -I/tmp/IM/ImageMagick-6.9.2-10/png -I/tmp/IM/ImageMagick-6.9.2-10/wand
PCFLAGS         = 
DEFS            = -DHAVE_CONFIG_H
LDFLAGS         =  -L/tmp/IM/ImageMagick-6.9.2-10/jpeg/.libs -L/tmp/IM/ImageMagick-6.9.2-10/jpeg -L/tmp/IM/ImageMagick-6.9.2-10/magick -L/tmp/IM/ImageMagick-6.9.2-10/png/.libs -L/tmp/IM/ImageMagick-6.9.2-10/png -L/tmp/IM/ImageMagick-6.9.2-10/wand
LIBS            = 
CXX             = g++
CXXFLAGS        = -g -O2 -D_THREAD_SAFE -pthread
FEATURES        = DPC Cipher
DELEGATES       = mpeg jpeg
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here is how I would install ImageMagick from source on OSX.

1. Install Xcode

First, you are going to need the Apple compiler and development tools whatever you do. So, start the AppStore which looks like this:

enter image description here

and download Xcode for free - it looks like this:

enter image description here

2. Install Command Line Tools

Once you have Xcode installed, you need to install the command-line tools (i.e. clang, clang++, make) like this:

xcode-select --install

3. Choose Your Method - homebrew or a Life of Agony

Now you need to choose how you are going to proceed. The simplest option, by miles and miles and miles, is to use homebrew. The other method is self-descriptive.

3a. homebrew Method

Go to the homebrew website and copy and paste the one-liner there into your Terminal - I won't show it here because it may change and I want you and future readers to use the current command. Once homebrew is installed, you just do this to choose your ImageMagick options:

brew options imagemagick

--with-fftw
    Compile with FFTW support
--with-fontconfig
    Build with fontconfig support
--with-ghostscript
    Build with ghostscript support
--with-hdri
    Compile with HDRI support
--with-jp2
    Compile with Jpeg2000 support
--with-liblqr
    Build with liblqr support
--with-librsvg
    Build with librsvg support
--with-libwmf
    Build with libwmf support
--with-little-cms
    Build with little-cms support
--with-little-cms2
    Build with little-cms2 support
--with-openexr
    Build with openexr support
--with-openmp
    Compile with OpenMP support
--with-pango
    Build with pango support
--with-perl
    enable build/install of PerlMagick
--with-quantum-depth-16
    Compile with a quantum depth of 16 bit
--with-quantum-depth-32
    Compile with a quantum depth of 32 bit
--with-quantum-depth-8
    Compile with a quantum depth of 8 bit
--with-webp
    Build with webp support
--with-x11
    Build with x11 support
--without-freetype
    Build without freetype support
--without-jpeg
    Build without jpeg support
--without-libpng
    Build without libpng support
--without-libtiff
    Build without libtiff support
--without-magick-plus-plus
    disable build/install of Magick++
--without-opencl
    Disable OpenCL

and then having selected your options, you install with

brew install imagemagick --with-perl --with-librsvg

or whatever you want. Then you are finished and you don't need to read the following torture!

Later on, upgrades are simple:

brew update && brew upgrade --all

Problem-solving is simple:

brew doctor

Uninstallation is simple:

brew rm imagemagick

3b. Life of Agony™ Method

Ok, I see you sadly decided on a Life of Agony™, so be it. I hope you know tar, bash, environment variables, gzip, make, curl. Now would be a good time to think again and use homebrew after all....

Sure you want to proceed? Ok, the general idea is to decide what features you need, install the features first, then install ImageMagick.

4. Set up a build area and environment

Set up two directories and 2 environment vars in your $HOME/.profile. These will be the build area where you build software and the sw area where you install your local software to:

export MSBUILD=$HOME/build
export MSSW=$HOME/sw

Now source your profile into your current session with

. $HOME/.profile

or just log out and log back in so that the variables above take effect.

Next create the two directories:

mkdir "$MSBUILD" "$MSSW"

5. Consider Features you need

Now consider what features you need:

5.1 Feature = PNG Support

If you need PNG support, you need zlib first. In your web-browser, go to the zlib website and find the name of the latest version. Then in Terminal:

cd $MSBUILD
curl -O -J -L http://sourceforge.net/projects/libpng/files/zlib/1.2.8/zlib-1.2.8.tar.xz/download

which gets you this zlib-1.2.8.tar.xz (or similar) which you can unpack and install with:

tar xvfJ zlib*.tar.xz          # Unzip and untar what you downloaded
cd zlib*[0-9]                  # Change directory to wherever it unpacked to
./configure --prefix="$MSSW"   # Configure with the necessary prefix
make
make install

Now you want libpng which you do with:

curl -O -J -L http://sourceforge.net/projects/libpng/files/latest/download?source=files

which gets you this (or similar):

libpng-1.6.17.tar.xz

which you install with this command:

tar xvfJ libpng*xz             # Unpack and untar whatever you downloaded
cd libpng*[0-9]                # Change directory to wherever it unpacked to
./configure --prefix="$MSSW"   # Configure with the necessary prefix
make 
make install

5.2 Feature = TIFF Support

If you need TIFF support, use this:

cd $MSBUILD
curl -O -J -L ftp://ftp.remotesensing.org/libtiff/tiff-4.0.3.tar.gz
tar xvfz tiff*tar.gz             # Unzip and untar what you downloaded
cd tiff*[0-9]                    # Change directory to wherever it unpacked to
./configure --prefix="$MSSW"     # Configure with the necessary prefix
make
make install

5.3 Feature = WEBP Support

If you need WEBP support, use this:

cd $MSBUILD
curl -O -J -L http://downloads.webmproject.org/releases/webp/libwebp-0.4.3.tar.gz
tar xvfz libwebp*tar.gz          # Unzip and untar what you downloaded
cd libwebp*[0-9]                 # Change directory to wherever it unpacked to
./configure --prefix="$MSSW"     # Configure with the necessary prefix
make
make install

5.4 Feature = JPEG Support

If you need JPEG support, use this:

cd $MSBUILD
curl -O -J -L http://www.ijg.org/files/jpegsrc.v9a.tar.gz
tar xvfz jpeg*tar.gz                 # Unzip and untar what you downloaded
cd jpeg-9a                           # Change directory to wherever it unpacked to
./configure --prefix="$MSSW"         # Configure with the necessary prefix
make
make install

5.5 Feature - X11 or X Windows

As OSX no longer ships with an X11 server, you will need to install one yourself if you wish to use X11. Now, if you had taken my advice and used homebrew, you would be able to do:

brew cask install xquartz

and you would be finished. But you chose the Life of Agony ™ option, so you will have to figure out how to install XQuartz yourself.

6. ImageMagick itself

Once you have all the features you want installed, you can install ImageMagick. Get your copy here, then install like this:

cd $MSBUILD
gunzip ImageMagick.tar.gz
tar -xvf ImageMagick.tar
cd ImageMagick-6.9.1-2       # or wherever the tar-file extracted to

Now choose your options. How do you know the options available? You run:

./configure --help

and you will get a daunting array of options like this:

`configure' configures ImageMagick 6.9.2-10 to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
  -h, --help              display this help and exit
      --help=short        display options specific to this package
      --help=recursive    display the short help of all the included packages
  -V, --version           display version information and exit
  -q, --quiet, --silent   do not print `checking ...' messages
      --cache-file=FILE   cache test results in FILE [disabled]
  -C, --config-cache      alias for `--cache-file=config.cache'
  -n, --no-create         do not create output files
      --srcdir=DIR        find the sources in DIR [configure dir or `..']

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]

By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc.  You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
  --bindir=DIR            user executables [EPREFIX/bin]
  --sbindir=DIR           system admin executables [EPREFIX/sbin]
  --libexecdir=DIR        program executables [EPREFIX/libexec]
  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
  --libdir=DIR            object code libraries [EPREFIX/lib]
  --includedir=DIR        C header files [PREFIX/include]
  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
  --infodir=DIR           info documentation [DATAROOTDIR/info]
  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
  --mandir=DIR            man documentation [DATAROOTDIR/man]
  --docdir=DIR            documentation root [DATAROOTDIR/doc/ImageMagick]
  --htmldir=DIR           html documentation [DOCDIR]
  --dvidir=DIR            dvi documentation [DOCDIR]
  --pdfdir=DIR            pdf documentation [DOCDIR]
  --psdir=DIR             ps documentation [DOCDIR]

Program names:
  --program-prefix=PREFIX            prepend PREFIX to installed program names
  --program-suffix=SUFFIX            append SUFFIX to installed program names
  --program-transform-name=PROGRAM   run sed PROGRAM on installed program names

X features:
  --x-includes=DIR    X include files are in DIR
  --x-libraries=DIR   X library files are in DIR

System types:
  --build=BUILD     configure for building on BUILD [guessed]
  --host=HOST       cross-compile to build programs to run on HOST [BUILD]
  --target=TARGET   configure for building compilers for TARGET [HOST]

Optional Features:
  --disable-option-checking  ignore unrecognized --enable/--with opti

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...