Building with PNG Delegate problems

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
HairyDalek
Posts: 6
Joined: 2016-03-07T06:10:54-07:00
Authentication code: 1151

Building with PNG Delegate problems

Post by HairyDalek » 2016-03-08T02:54:37-07:00

I’m trying to build ImageMagick with png and jpeg delegates on a Mac - OSX 10.11.3 - and it’s not going well.

Further to my attempts to build a completely standalone version of ImageMagick (see my previous post on the matter), I am having real problems getting the png delegate included. The version that is used is always one in /opt/local. I have read on this forum that if you rename the local folder to local~ that the png delegate in the imagemagick folder that you are compiling from will be used. This seems not to be the case. When I do this, and then try to run convert with a png file, the following happens:

Code: Select all

$ /Users/paul/Desktop/ImageMagick-Final/bin/convert /Users/paul/Desktop/temp.png /Users/paul/Desktop/temp.png 
convert: NoDecodeDelegateForThisImageFormat `PNG' @ error/constitute.c/ReadImage/501.
convert: NoImagesDefined `/Users/paul/Desktop/temp.png' @ error/convert.c/ConvertImageCommand/3252.
Before I build ImageMagick, I unpack the pnglib.tar.gz file, rename it png, put that in the ImageMagick source folder. I run configure in the png folder, then make and make install (There seems to be differences in instructions - some say use just make, others say use make then make install). There’s a prefix attribute that points to the png folder. Then I run configure in the ImageMagick folder, make and make install again (I again use a prefix to install the final build into an empty folder).

When I run otool -L /path/to/convert I get a whole list of dependencies, most of them in /opt/local - not good because you can not be sure that that folder and the files referenced will be on other machines.

Because I have been trying loads of different things - all based on suggestions from various posts in this forum and other places, I wrote a script to automate this:

Code: Select all

#!/usr/bin/env bash
MYPATH=$PATH
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
cd ~/Desktop
mkdir ImageMagick-Final
tar xvzf ImageMagick.tar.gz
cd ImageMagick-6.9.3-7
tar xvzf ~/Desktop/jpegsrc.v9a.tar.gz
mv jpeg-9a jpeg
tar xvzf ~/Desktop/libpng-1.6.21.tar.gz
mv libpng-1.6.21 png
cd png
./configure --disable-shared --disable-dependency-tracking --prefix="/Users/paul/Desktop/ImageMagick-6.9.3-7/png" 
make clean;make
make install
cd ../jpeg
./configure --disable-shared --disable-dependency-tracking --prefix="/Users/paul/Desktop/ImageMagick-6.9.3-7/jpeg" 
make clean;make
make install
cd ../
./configure --disable-installed --disable-shared --enable-delegate-build --disable-dependency-tracking --with-x=no --without-perl --with-freetype=no --with-jp2=no --with-magick-plus-plus=no --without-frozenpaths --with-bzlib=no --with-png=yes --with-jpeg=yes --prefix=/Users/paul/Desktop/ImageMagick-Final LDFLAGS="-L/Users/paul/Desktop/ImageMagick-6.9.3-7/png -L/Users/paul/Desktop/ImageMagick-6.9.3-7/jpeg" CPPFLAGS='-I/Users/paul/Desktop/ImageMagick-6.9.3-7/png/include -I/Users/paul/Desktop/ImageMagick-6.9.3-7/jpeg/include' 
make clean;make
make install
echo ""
echo $PATH
export PATH=$MYPATH
echo ""
echo $PATH
My last attempt, I restored to resetting the variable PATH to its default to see if that would make a difference. It didn’t. This time, as with renaming /opt/local, the png delegate was not included.

What I want is for the png and jpeg libraries to be part of a portable ImageMagick - one that can be put in an app (in my case one created in LiveCode) and for it to work without the need for the user to install tools like ImageMagick themselves. I am finding this getting very frustrating now. I’m sure I’ve missed something out, but I can’t see what. I’ve tried so many permutations of parameters in various ./configure calls that I really feel that this might not be possible - yet I read that it is.

snibgo
Posts: 12010
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Building with PNG Delegate problems

Post by snibgo » 2016-03-08T03:45:55-07:00

I can't really help, but I suggest you look at the output of "./configure" of the ImageMagick build. Look at both the output sent to stdout, and the file "config.log" for more detail. This will tell you if the IM build found the libraries, and may give some insight.

I suppose the delegates have similar configure logs.
snibgo's IM pages: im.snibgo.com

HairyDalek
Posts: 6
Joined: 2016-03-07T06:10:54-07:00
Authentication code: 1151

Re: Building with PNG Delegate problems

Post by HairyDalek » 2016-03-08T05:17:27-07:00

snibgo wrote:I can't really help, but I suggest you look at the output of "./configure" of the ImageMagick build. Look at both the output sent to stdout, and the file "config.log" for more detail. This will tell you if the IM build found the libraries, and may give some insight.

I suppose the delegates have similar configure logs.
Thank you! I waded through the config.log file for ImageMagic, and found some helpful hints (I ran it with -v for verbose output), and it dropped a hint. It was looking for a file called libpng.c and it could not find it. It suggested adding the path to the folder that contains that file to PKG_CONFIG_PATH which is what I did. I managed to get a build of ImageMagick that processes PNGs - and importantly it works on my wife’s Mac which is far more an “out of the box” machine than mine is.

My amended .sh script, just in case it’s of any use to others, is this:

Code: Select all

#!/usr/bin/env bash
MYPATH=$PATH
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
cd ~/Desktop
mkdir ImageMagick-Final
tar xvzf ImageMagick.tar.gz
cd ImageMagick-6.9.3-7
tar xvzf ~/Desktop/jpegsrc.v9a.tar.gz
mv jpeg-9a jpeg
tar xvzf ~/Desktop/libpng-1.6.21.tar.gz
mv libpng-1.6.21 png
cd png
./configure --disable-shared --disable-dependency-tracking --enable-static=no --prefix="/Users/paul/Desktop/ImageMagick-6.9.3-7/png" 
make clean;make
make install
cd ../jpeg
./configure --disable-shared --disable-dependency-tracking --enable-static=no  --prefix="/Users/paul/Desktop/ImageMagick-6.9.3-7/jpeg" 
make clean;make
make install
cd ../
export PKG_CONFIG_PATH=/Users/paul/Desktop/ImageMagick-6.9.3-7/png/
./configure --disable-installed --disable-shared --enable-delegate-build --disable-dependency-tracking --with-x=no --without-perl --with-freetype=no --with-magick-plus-plus=no --without-frozenpaths --with-bzlib=no --with-png=yes --with-jpeg=yes --prefix=/Users/paul/Desktop/ImageMagick-Final  LDFLAGS="-L/Users/paul/Desktop/ImageMagick-6.9.3-7/png" CPPFLAGS='-I/Users/paul/Desktop/ImageMagick-6.9.3-7/png' 
make clean;make
make install
echo ""
echo $PATH
export PATH=$MYPATH
echo ""
echo $PATH
I’ll check that what I have works in the environment I want it to later, but for now, this seems to give me what I want.

snibgo
Posts: 12010
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Building with PNG Delegate problems

Post by snibgo » 2016-03-08T05:39:17-07:00

Good stuff. Thanks for sharing your solution.

Not every problem reported in config.log is a real problem, as "./configure" often finds a workaround. But it can help to explain why the build isn't as we want.
snibgo's IM pages: im.snibgo.com

modrickthebrave
Posts: 6
Joined: 2016-07-31T20:14:49-07:00
Authentication code: 1151

Re: Building with PNG Delegate problems

Post by modrickthebrave » 2016-08-02T01:30:24-07:00

This is just an FYI post, but I was just able to get ImageMagick-7.0.2-6 PNG support working in a fully static build under Mac OS X 10.11.4 like so:

build and install both libz and libpng

open configure in editor and add this to disable the pkgconfig logic that does not work on OSX
have_png=yes
this must be just before the if test that defines PNG_DELEGATE, search for this "PNG_DELEGATE" string to find it

now back in the shell, run configure, note that this depends on where your build dir is

Code: Select all

export INS=`cd ../../install;pwd`
export CPPFLAGS="-I${INS}/include"
export LDFLAGS="-L${INS}/lib -lpng16 -lz"
../../ImageMagick-7.0.2-6/configure --prefix=${INS} --disable-shared --enable-static --enable-delegate-build \
--without-tiff --without-freetype --with-x=no --with-png --with-jpeg --with-zlib
make
make install

utnuc
Posts: 12
Joined: 2014-09-17T06:41:13-07:00
Authentication code: 6789

Re: Building with PNG Delegate problems

Post by utnuc » 2016-09-03T18:34:05-07:00

@modrickthebrave, When I try your method I'm unable to get the compile to include the png delegate still. Getting the following warning on compile:
libtool: warning: '/usr/local//lib/libpng16.la' seems to be moved
Here's the commands I ran:

Code: Select all

export INS="/usr/local"
export CPPFLAGS="-I${INS}/include"
export LDFLAGS="-L${INS}/lib -lpng16 -lz"
./configure --prefix=${INS} --disable-shared --enable-static --enable-delegate-build \
--without-tiff --without-freetype --with-x=no --with-png --with-jpeg --with-zlib
make
make install
All my delegate builds defaulted to install under /usr/local/include and /usr/local/lib. Thoughts on what i'm doing wrong?

User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Building with PNG Delegate problems

Post by glennrp » 2016-09-04T15:44:16-07:00

Here's what I do on Ubuntu 16:04:
First, I cd into the libpng source directory and build libpng with

Code: Select all

configure --prefix=/home/glennrp/IM --with-libpng-prefix=IM
make
make install
The first "--prefix" tells where to install libpng (in this case, an "IM" subdirectory in my home directory), and the "--with-libpng-prefix=IM" puts "IM" at the beginning of each exported function name.

Then I cd into the IM source directory and build ImageMagick with

Code: Select all

MAGICK_HOME=`pwd` export MAGICK_HOME 
PKG_CONFIG_PATH=/home/glennrp/IM/lib/pkgconfig export PKG_CONFIG_PATH
./configure [other options]
make
make install
This uses the libpng that I just installed, and the exported function names are different from those in the ancient "system" libpng that exists on my machine, so that old library doesn't interfere. Hopefully that will work on your MacOS....

Post Reply