15
votes

I'm trying to put watermark on iOS app's appIcon. For that I'm following [Ray's][1] blog and I installed ImageMagick using binary release from [here][2]. I also added /bin and /lib in my paths using sudo nano /etc/paths so convert command seems to be working.

The problem statement: when I use convert command from tutorial I get the following error

dyld: Library not loaded: /ImageMagick-7.0.1/lib/libMagickCore-7.Q16HDRI.0.dylib
  Referenced from: /Users/Username/Library/ImageMagick-7.0.1/bin/convert
  Reason: image not found
Abort trap: 6

Even though the image is there the error is "image not found." Any idea community ? [1]: https://www.raywenderlich.com/1716-how-to-change-your-app-icon-at-build-time [2]: https://www.imagemagick.org/script/download.php#macosx

3
Looks like DYLD_LIBRARY_PATH needs to be defined.emcconville
On my system, I have DYLD_LIBRARY_PATH, but I still get the error.William Jockusch

3 Answers

17
votes

I had the same problem. What worked for me was removing from the $PATH a problematic previous installation, then reinstalling:

brew update && brew upgrade
brew remove imagemagick
brew install imagemagick

Then when I ran:

which convert

I finally got the brew version:

/usr/local/bin/convert

And when I ran the command from the tutorial:

convert [email protected] -fill white -font Times-Bold -pointsize 18 -gravity south -annotate 0 "Hello World" test.png

I got the Hello World image.

3
votes

UPDATE

I've checked the page you got your package from, and it looks like my hypothesis was correct - you're missing a path variable, MAGICK_HOME. Luckily it seems easy to correct.

You need to get the absolute path of the directory where ImageMagick is. In a pinch, you can search for it everywhere - run this from command line:

find / -type d -name "ImageMagick-7.0.3" 2>/dev/null

It should answer with exactly one ImageMagick directory (unless you installed it more than once in different places, in which case you need to determine which of the two is the "correct" package).

As an alternative, if you issue the command

which convert

it should tell you the full path of the convert executable, which should be in the bin subdirectory of the ImageMagick installation.

Suppose that it says that the directory is

/Users/lserni/Desktop/test/ImageMagick-7.0.3

then before using ImageMagick in the terminal, you need to issue these commands:

export HOME=/Users/lserni/Desktop/test
export MAGICK_HOME="$HOME/ImageMagick-7.0.3"
export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib/"

Now you can try ImageMagick:

convert logo: logo.gif
identify logo.gif

It should give something like,

logo.gif GIF 640x480 640x480+0+0 8-bit sRGB 256c 28.6KB ...

ORIGINAL ANSWER

dyld: Library not loaded: /ImageMagick-7.0.1/lib/libMagickCore-7.Q16HDRI.0.dylib Reason: image not found

There are several possible reasons. The one that strikes me as the likeliest is that the library is, actually, not "there" -- "there" meaning a directory called "ImageMagick-7.0.1" in the volume root. The library might be in /usr, or /lib, or /opt, but the error above says that it's looking for it in /ImageMagick-7.0.1.

Try typing this in the terminal to query that path:

ls -la /ImageMagick-7.0.1/lib/libMagickCore-7.Q16HDRI.0.dylib

I've found a reference implying that you can redirect a ldpath from an executable if it contains the wrong path, but I have not yet tried it:

install_name_tool -change /ImageMagick-7.0.1/lib/libMagickCore-7.Q16HDRI.0.dylib /usr/local/lib/libMagickCore-7.Q16HDRI.0.dylib /usr/local/bin/NameOfImageMagickBinaryYou'ReCalling

(the binary is probably /usr/local/bin/convert )

...and, possibly, there are other libraries and other IM binaries with the same problem.

Another possibility is that the library is there, but it's trying to load, in turn, other libraries that aren't there. libPNG, JPEGlib, libTIFF and so on are all likely candidates. While you can delve into the matter using tools such as strace, perhaps it's best if you check the installation from the beginning.

Finally, you might have a permission error either in the dylib, or in the path leading to that dylib. This can happen if you install as root (or the installation runs as root), the library directories are created with more secure permissions (e.g. 750 instead of 755), and then you run the application as a different and/or less privileged user/group.

If you installed ImageMagick through Homebrew, check also HB's configured paths. Your symptoms remind me very much of what would happen if the install script ran with --prefix= instead of --prefix=/usr/local.

2
votes

IMHO, the very easiest way to install, configure, uninstall ImageMagick and many, many other packages on OS X is to use homebrew.

Step 1

Go to homebrew website and copy the one-liner and paste it into your Terminal and run it.

Step 2

Now, decide what package you want to search for and install - ImageMagick, Redis, pandoc, gawk etc and look for the package with a command like one of these:

brew search magick
brew search redis
brew search gawk

Step 3

Now check which options you would like for ImageMagick:

brew options imagemagick

Sample Output

--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-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-opencl
    Compile with OpenCL support
--with-openexr
    Build with openexr support
--with-openjpeg
    Build with openjpeg support
--with-openmp
    Compile with OpenMP support
--with-pango
    Build with pango support
--with-perl
    Compile with 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
--with-zero-configuration
    Disables depending on XML configuration files
--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-modules
    Disable support for dynamically loadable modules
--without-threads
    Disable threads support
--HEAD
    Install HEAD version

Step 4

Install with the options you select:

brew install imagemagick --with-fftw --with-openmp --with-pango

And then everything is good to go.

Update and Upgrade Packages

If you want to update your copy of homebrew and update all your packages, use:

brew update && brew upgrade

Remove packages

If you want to remove ImageMagick, use:

brew rm imagemagick

Re-install Packages with different options

If you want to re-install ImageMagick with quantum depth 32 (Q32), for example, use:

brew reinstall imagemagick --with-quantum-depth-32

Troubleshooting

If you have any problems at all with homebrew, just ask the good doctor what is wrong and you will get a report on everything that is not good:

brew doctor

Neat packages

Some of my favourite packages are:

ack, ansiweather, arpack, astyle, atk, atkmm, autoconf, basex, bash, boost, c-ares, cairo, cairomm, cimg, cmake, coreutils, cpanminus, curl, dbus, dcraw, doxygen, eigen, epstool, exact-image, exiftool, exiv2, faac, feh, ffmpeg, fftw, findutils, flac, fltk, fontconfig, fortune, freeimage, freetype, fswatch, gawk, gcc, gd, gdb, gdbm, gdk-pixbuf, geoip, gettext, ghostscript, giflib, gifsicle, gl2ps, glib, glibmm, glpk, gmp, gnu-sed, gnuplot, gnutls, gobject-introspection, graphicsmagick, grep, gsettings-desktop-schemas, gtk+3, harfbuzz, hdf5, hicolor-icon-theme, hiredis, icu4c, ilmbase, imagemagick, imlib2, isl, jasper, jbig2dec, jhead, jpeg, jpeg-turbo, jq, lame, leptonica, lftp, libagg, libbtbb, libcroco, libepoxy, libevent, libexif, libffi, libgcrypt, libgpg-error, libgsf, libmpc, libogg, libpng, librsvg, libsigc++, libsvg, libsvg-cairo, libtasn1, libtiff, libtool, libusb, libusb-compat, libvo-aacenc, libvorbis, libxml2, libyaml, lighttpd, little-cms, little-cms2, llvm, lua, lynx, lz4, mad, matplotlib, metis, mpfr, nanomsg, net-snmp, netpbm, nettle, ngrep, nmap, node, numpy, octave, oniguruma, opencv3, openexr, openjpeg, openjpeg21, openssl, orc, p7zip, pandoc, pango, pangomm, parallel, pcre, pdfgrep, perl, perlmagick, php56, php56-amqp, php56-imagick, pixman, pkg-config, platypus, plotutils, pngcheck, pngcrush, pngquant, poppler, popt, potrace, pstoedit, py2cairo, pygobject3, pyqt, pyqt5, python, python3, qhull, qrupdate, qscintilla2, qt, qt5, rabbitmq-c, readline, redis, rename, rocksdb, ruby, sane-backends, sdl, shared-mime-info, sip, smartmontools, snappy, sox, sqlite, sqliteman, suite-sparse, suite-sparse421, svg2png, swig, szip, tag, tbb, tesseract, tmux, transfig, tree, ufraw, unixodbc, utf8proc, veclibfort, vips, webkit2png, webp, wget, wireshark, x264, xmlstarlet, xvid, xz, youtube-dl, bar