6

I am trying to create animated visualization in R and people say needs to install ImageMagick. However, it seems that current Mac no longer support x11, while ImageMagick just needs X11 server on Mac. Install ImageMagick

I have also tried brew install imagemagick --with-x11, doesn't work and only returned so many errors.

Apples says need to use XQuartz to replace x11. I have XQuartz, but when I turned on it, typed the same commands here, still give me the same error

display: delegate library support not built-in '' (X11) @ error/display.c/DisplayImageCommand/1891.

So, my questions is, how to install and use ImageMagick with Mac XQuartz?

Cherry Wu
  • 3,844
  • 9
  • 43
  • 63
  • Before you do any development on macOS, you need to install **Xcode command line tools**. Go to **AppStore** and download **Xcode** for free. Then, in Terminal, run `xcode-select --install`. Then try the **homebrew** installation again. – Mark Setchell Jun 19 '17 at 07:59
  • I have xcode installed – Cherry Wu Jun 19 '17 at 16:11
  • 1
    Good, I hope you have run `xcode-select --install` since any OS upgrades. Next, I would do `brew update; brew rm imagemagick; brew install imagemagick --with-x11` – Mark Setchell Jun 19 '17 at 17:17
  • Then run `identify -version` and check you get exactly the same version as when you run `brew info imagemagick`. Also `which convert` should tell you `/usr/local/bin/convert` – Mark Setchell Jun 19 '17 at 17:21
  • Did you "export DISPLAY=:0" in your .profile or .bash_profile file (without the quotes)? – fmw42 Jun 19 '17 at 19:06
  • Yes I tried that – Cherry Wu Jun 19 '17 at 19:21
  • 1
    Try starting `xclock &` before you use ImageMagick to make sure your X11 environment is working and able to display X11 windows. – Mark Setchell Jun 19 '17 at 20:20
  • @MarkSetchell, I just got the chance to try what you said, it is in fact the solution to help me install `imagemagick`. And when I typed `xclock &`, XQuartz started to run as expected. Thank you very much! you can write it as solution, so that I can close this question. – Cherry Wu Jun 24 '17 at 07:17

2 Answers2

5

I created a Homebrew ImageMagick X11 formula that can be used like this:

brew uninstall imagemagick  # without X11 support
brew install --cask xquartz
brew install tlk/imagemagick-x11/imagemagick 

Note that homebrew-core used to support formula options such as --with-x11 in order to enable a configure option of the same name. This is no longer the case as the Homebrew maintainer(s) decided to remove formula options from homebrew-core formulas.

tlk
  • 71
  • 3
  • 8
  • 1
    I install from source after installing all my delegates from MacPorts and do not get any error messages. I just install Xcode Tools and then XQuartz and do not include --with X11. That works to display images for me. – fmw42 Jan 13 '20 at 18:01
2

Updated Answer

Note that things have changed a bit since I wrote this answer, Homebrew no longer supports installation options such as --with-x11. One possibility, pointed out in the comments by @MattWhite was to install ImageMagick interactively:

brew install imagemagick -i;
./configure --disable-osx-universal-binary --prefix=/usr/local/Cellar/imagemagick/7.0.8-66 --disable-silent-rules --with-x11
make install
exit

Another option that occurred to me was that, rather than installing all of XQuartz, you could just add your own delegate that uses macOS's built-in Preview app and tell ImageMagick to use that, i.e. delegate to it. This means you can do things like:

magick SomeImage.png -crop 100x100+10+10 display:

For this to work, you need to find your delegates.xml file. I used this:

magick -list delegate | awk '/^Path/ {print $2}'

and mine is at:

/opt/homebrew/Cellar/imagemagick/7.1.0-16/etc/ImageMagick-7/delegates.xml

Then I edited that file and added a line very close to the end, but just above the last line like this:

<delegate decode="miff" encode="display" spawn="True" command="magick %i %u.png ; /usr/bin/open -a Preview %u.png"/>

That converts any file formats that ImageMagick knows into a PNG which the Preview app understands and should be able to represent most images, even those with 16-bit depth and transparency.

Original Answer

In general, to use ImageMagick with X11, you will probably be most likely to succeed if you follow the following steps:

Step 1 - Install or update Xcode command line tools

It is important that your developer tools are up-to-date, especially if you have updated your macOS version since setting them up originally. You can do this with:

xcode-select --install

Step 2 - Ensure ImageMagick is correctly installed

The easiest way to do this is first to ensure that old versions of ImageMagick are removed and cleaned up and that you then install (or re-install) with the latest version:

brew update                           # update homebrew itself 
brew rm imagemagick                   # remove old IM versions
brew install imagemagick --with-x11   # install latest IM version including X11 support

Step 3 - Check

If you have been trying for ages to install ImageMagick, you may have left some old versions lying around. It is important that you use the homebrew-installed version in /usr/local/bin, so check you are running the version you expect with the following:

which convert           # should report "/usr/local/bin/convert"
which magick            # should report "/usr/local/bin/magick"

identify -version       # should report same version as next command
brew info imagemagick

Step 4 - Start X11

Start X11, it is probably easiest to fire up xclock, which not only starts X11, but also checks everything X11 is running and your X11 environment is configured correctly:

xclock & 

Step 5 - Run ImageMagick X11

Now you can test your ImageMagick configuration, without needing any test images as follows - since the wizard: image is built-in:

display wizard:
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • I would add just a bit to Mark's outline. I usually just start Xquartz itself before trying to display an image with ImageMagick. I also add "export DISPLAY=:0" to my .profile or .bash_profile file (without the quotes) – fmw42 Jun 26 '17 at 16:25
  • @fmw42 Hi Fred, Thanks for your top tips. By the way, you can highlight `code` in comments and answers by surrounding it with backticks, and do *italics* by surrounding with asterisks (no spaces) and finally you can **bold** text by surrounding with double asterisks. – Mark Setchell Jun 26 '17 at 16:40
  • Thanks, Mark. I did not know that. I will have to study the markup docs. – fmw42 Jun 26 '17 at 17:57
  • When you are using `brew update`, if got error like "Error: The /usr/local directory is not writable", try command `sudo chown -R $(whoami):admin /usr/local` to get the permission, then try `brew update`. After that, type `sudo chown root:wheel /usr/local` to change permission back – Cherry Wu Jun 27 '17 at 03:27
  • 1
    The `--with-x11` option isn't working for me. https://discourse.brew.sh/t/cant-install-imagemagick-with-options/4470 – dreeves Mar 26 '19 at 21:04
  • 5
    @dreeves **homebrew** has completely changed since I wrote this answer. AFAIK, packages no longer have options. – Mark Setchell Mar 26 '19 at 21:06
  • You can install it with brew in interactive mode: `brew install imagemagick -i; ./configure --disable-osx-universal-binary --prefix=/usr/local/Cellar/imagemagick/7.0.8-66 --disable-silent-rules --with-x11; make install; exit` – Matt White Oct 04 '19 at 16:11
  • @MattWhite Brilliant! Thank you for sharing. – Mark Setchell Oct 04 '19 at 16:27