How to use ImageMagick with XQuartz - macos

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?

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.

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:

Related

Installing gnu plot for macOS High Sierra

How does one install a runnable version of gnu plot in macOS high Sierra?
I am looking for a way to make this work with the GUI, but even just getting the terminal script to run would be a success.
Thanks!
The Brew implementation of gnuplot is not really usable because it no longer supports the necessary terminals (e.g., you can no longer provide --with-aquaterm or --with-x11 during installation).
However, the MacPorts package manager has a usable install for gnuplot (it's safe to have both Brew and MacPorts installed). https://www.macports.org/
After intalling AquaTerm, I used the following to install gnuplot, and all is working as expected:
sudo port install gnuplot +aquaterm
I'm using macOS Mojave 10.14.4.
It's easy enough with homebrew.
First, install Xcode command line tools:
xcode-select --install
Then install homebrew by going to homebrew website and copying and pasting the one-liner installation script. I don't want to paste that line here in case it changes down the line, so get the latest from the homebrew website.
Now you have a full package manager that allows you to find, install, update and delete thousands of packages. So you can easily find gnuplot or anything else with:
brew search gnuplot
Once you have found your package, check the avaiable options with:
brew options gnuplot
Sample Output
--with-aquaterm
Build with AquaTerm support
--with-cairo
Build the Cairo based terminals
--with-qt
Build with qt support
--with-wxmac
Build wxmac support. Need with-cairo to build wxt terminal
--with-x11
Build with x11 support
Now install with some sensible options for graphical plots:
brew install gnuplot --with-qt --with-x11
Always ensure your PATH starts with /usr/local/bin for homebrew since that is where it installs programs. I put the following in $HOME/.profile. And I also set the GNUTERM environment variable:
export PATH=/usr/local/bin:$PATH
export GNUTERM=qt
Now run gnuplot:
gnuplot
Sample Run
Check out many useful packages, a nice new Python not Apple's old v2.7, a nice Linux-compatible sed not Apple's BSD version, a nice grep, a nice find, the brilliant GNU awk, ImageMagick, tmux, GNU Parallel, jhead, Poppler, exiftool, Mosquitto, pdfgrep, pngcrush, ZeroMQ... the list goes on...
#David Atri: gnuplot is not as standalone as you might think. Try to compile it from source and you will see how many options and dependencies it has.The main challenge in MacOSX is to get the PDF drivers running. The fact that you see many things as standalone is the good integration work made by the developers
brew is no longer support options.
You can still do "brew install gnuplot", but it will install with just the terminals that the person who wrote the homebrew formula wanted, not necessarily the ones you want.
Compiling gnuplot from the sources is still a nightmare, so you live with the brew-formula writer's choices, write your own brew formula (not completely trivial), or you struggle with huge pile of dependencies and try to compile from the sources.

imagemagick: brackets in file names 'No such file or directory' — Mac OS X

I've upgraded my Homebrew ImageMagick to 6.9.4-7 version (Mac OS 10.11.5), after which it doesn't understand brackets in file names anymore.
This command should consider the first frame of a picture:
identify -format '%wx%h,1' 'some_pic.jpg[0]'
For JPG it is actually just the picture, so the command is equivalent to:
identify -format '%wx%h,1' 'some_pic.jpg'
The bracket command works fine on my Ubuntu server and worked before on my Mac. But now it fails with
identify: unable to open image `some_pic.jpg[0]':
No such file or directory # error/blob.c/OpenBlob/2705.
Btw, this is the reason behind Paperclip::Errors::NotIdentifiedByImageMagickError on my local machine.
Manually installing imagemagick-6.9.3-10 via brew has fixed the problem. So I believe it's a bug in imagemagick.
PS:
To install specific version via brew, run
brew edit imagemagick
And edit these lines:
url "https://dl.bintray.com/homebrew/mirror/imagemagick-6.9.4-7.tar.xz"
mirror "https://www.imagemagick.org/download/ImageMagick-6.9.4-7.tar.xz"
sha256 "f54fc8dcdb328404d1f89ddebe75d603e22894d3786ca2f2a9677478135b4c86"
May not work if the version you choose (https://dl.bintray.com/homebrew/mirror/) is not compatible with the rest of the brew formula. Then you need to go deeper.
Remove the quote from 'some_pic.jpg' and then try to execute the command. It should run fine.

ImageMagick + El Capitan Unable to Locate Module

UPDATE: Solved with the solution here
I have spent the better part of my day trying to get ImageMagick to work with Grunt, with no luck. Grunt seems to be okay, but ImageMagick not so much, even though I've run the test on ImageMagick.org to make sure that it's installed correctly (I used HomeBrew for the install).
I get this error when trying to run a task:
Warning: Command failed: identify: unable to load module
'/usr/local/Cellar/imagemagick/6.9.2-4/lib/ImageMagick//modules-
Q16/coders/jpeg.la': file not found # error/module.c/OpenModule/1300.
identify: no decode delegate for this image format 'JPEG' #
error/constitute.c/ReadImage/501.
I've tried the solutions here and here, but none of them have helped.
(FYI I'm new to using the command line.)
Help?
As with any homebrew problem, I would suggest you run
brew doctor
first, to try and sort things out. It is an excellent diagnosis tool.
Now, to your specific problem... mmmm... the /opt/X11 part of your error message worries me because homebrew installs in /usr/local/bin and /usr/local/Cellar so your ImageMagick should not be looking anywhere in /opt at all. I guess you have installed freetype via MacPorts or some method other than homebrew.
I would suggest you install the freetype stuff using homebrew, i.e.
brew install freetype
Then I would suggest uninstalling any other freetype stuff you have installed any other way. Finally, I would suggest you check your PATH environment variable and make it point to /usr/local/bin before anything in /opt. You will need to log out and back in for the new PATH to take effect - you can check your PATH like this:
echo $PATH
and change it by editing $HOME/.profile if you need to.
The homebrew version of freetype provides version 19 of the library and is therefore compatible with the homebrew ImageMagick version.
Also, I am a little disconcerted by the X11 part in your error message - modern Macs don't really use X11 any more and it doesn't ship with OSX. Let's see if the above ideas sort you out before worrying about that too much though - unless you know, and can say for sure, that you need X11.

how to install libX11 on OSx 10.9?

I am trying to install ROOT (cern.root.ch). When I run ./configure , I get a message that libX11 is missing and must be installed.
I did some research and found that I need to install
) XQuartz (I already have the latest version.)
) Command line tools in Xcode.
I tried installing Command Line Tools from apple's developer website. The installation goes through smoothly but how do I know whether it has been installed? I still get libX11 missing error with root's configure command.
I also tried xcode-select --install and it once went through smoothly and then later again gives error saying this package is no longer maintained - or something of that sort.
I understand I may have multiple installations... But I am still facing the problem of not having libX11 and not being able to install ROOT.
Thanks,
Hershal.
This link and the one referenced in it suggests you use homebrew (brew) to install it
$ ruby <(curl -fsS https://raw.github.com/mxcl/homebrew/go)
$ brew doctor
Remember to add the Homebrew directory to your PATH by adding the directory (found with brew --prefix) to your .bashrc, .zshrc or whatever shell file you’re using (.bashrc is the OS X default). We’ll also add the XQuartz binaries to the PATH in case anything needs them in the future.
export PATH=/usr/local/bin:/opt/X11/bin:$PATH
Start a new Terminal session to pick up the changes.
Now that Homebrew is installed, we can use it to install the required dependencies. Each may take some time as Homebrew generally compiles from source.
$ brew install gfortran # Fortran compiler
$ brew install python # Python interpreter
$ brew install pcre # Regular Expressions library
$ brew install fftw # Fast Fourier Transforms
$ brew install cmake # Cross-platform make
install root
$ brew tap homebrew/science
$ brew install --with-cocoa root
You don't say whether you have installed XCode as well as the commandline tools but I think you will need it

Gnuplot cannot recognize AquaTerm even I have it installed on OSX 10.8.5 [duplicate]

I've installed Octave and gnuplot via Homebrew, and downloaded AquaTerm.dmg.
When I try to plot, I get the following message:
octave:4> plot(x,y)
gnuplot> set terminal aqua enhanced title "Figure 1" font "*,6"
^
`line 0: unknown or ambiguous terminal type; type just 'set terminal' for a list`
In a bash terminal set terminal, set Terminal, set term, (and the same, followed by "aqua" too) etc gives nothing.
I've tried plotting again from octave having the "AquaTerm" already open, but nothing. I've tried plotting directly from gnuplot but same problem.. How can I do this "set terminal aqua"?
Gnuplot starting message says "Terminal type set to 'x11'" but no idea how to change it, the previous commands didn't work neither.
Since AquaTerm wasn't installed from Homebrew maybe octave/gnupot can't find it... but no idea.
Any guess? Thanks!
I had to add setenv("GNUTERM","X11") to OCTAVE_HOME/share/octave/site/m/startup/octaverc (OCTAVE_HOME usually is /usr/local) to make it work permanently.
Solution found and more details on: http://www.mac-forums.com/forums/os-x-apps-games/242997-plots-octave-dont-work.html
I've ran into a similar issue with Octave-cli, version 3.8.0, on OS X 10.9.1. Observing how Octave-gui could still plot charts, and reading up the answer with octaverc, I've got plotting to work from Octave-cli by adding a line with setenv("GNUTERM","qt") to /usr/local/octave/3.8.0/share/octave/site/m/startup/octaverc
I didn't have to re-install gnuplot or other dependencies.
Setting the terminal type to x11 would solve the problem, but if you want to get AquaTerm working with gnuplot here's how:
First we need to uninstall the existing installation of gnuplot, open up a terminal and run this command.
brew uninstall gnuplot
Download AquaTerm from here: http://sourceforge.net/projects/aquaterm/ and install as you would any OSX application.
From here on, there are two ways to get gnuplot happy with aquaterm, Method 1 is easier, but didn't work for me because my AquaTerm installation didn't create the correct symlinks in /usr/local/lib, Method 2 is the one that worked for me, and I am sharing the steps I took to get it working.
Method 1: Simply reinstall gnuplot after installing AquaTerm seems to fix this issue for people.
brew install gnuplot
Go to the verify step to see if everything worked, if not, follow method 2
Method 2: This method is more advanced, but guaranteed to work if you are patient.
Essentially gnuplot cannot locate the AquaTerm library files, that's why aqua doesn't show up as a terminal type option after we installed gnuplot. We need to modify the homebrew recipe for gnuplot to enable aquaterm support, open up the brew recipe for gnuplot by typing:
brew edit gnuplot
And add these lines as shown in this github commit message, this will enable the brew option for gnuplot to include aquaterm https://github.com/mxcl/homebrew/issues/14647#issuecomment-21132477
Check to see if the proper AquaTerm library symlinks exist by doing these checks:
ls /usr/local/lib/libaquaterm*
ls /usr/local/include/aquaterm/*
The first line above should return some *.dylib files, the second line above should return
some *.h files, if they do not exist run these commands from terminal:
sudo ln -s /Library/Frameworks/AquaTerm.framework/Versions/A/AquaTerm /usr/local/lib/libaquaterm.dylib
sudo ln -s /Library/Frameworks/AquaTerm.framework/Versions/A/AquaTerm /usr/local/lib/libaquaterm.1.0.0.dylib
sudo ln -s /Library/Frameworks/AquaTerm.framework/Versions/A/Headers/* /usr/local/include/aquaterm/.
This is necessary sometimes as the installer for AquaTerm can't create the symlinks in the correct places due to permission issues. Once the /usr/local/ symlinks are created, reinstall gnuplot like this:
brew install gnuplot --with-aquaterm # (formerly --aquaterm in old versions)
Verify that gnuplot can see aquaterm using the steps below and happy plotting!
Verify: that gnuplot was configured with AquaTerm correctly by launching gnuplot in terminal
gnuplot
Type this in the gnuplot terminal
gnuplot> set term
Look for the line
Available terminal types:
aqua Interface to graphics terminal server for Mac OS X
...
If you see the that line above, then you are done, gnuplot is configured correctly and everybody's happy.
I found a way to generate the plots with octave, although is not using AquaTerm but x11. The problem was that Octave was "forcing" gnuplot to use aquaterm to plot. Instead of installing and integrating aquaterm into gnuplot, in octave typed: setenv GNUTERM x11. With this, plots are generated with x11 which is already in the terminal list of gnuplot (set terminal). I know it's a patch, but finally I don't mind aquaterm or x11, I just want plots to be generated
set terminal or set term is gnuplot command.
You just need to run gnuplot from command line to get access to the gnuplot shell.
However, this didn't work for me, neither did the setenv("GNUTERM","x11") in /usr/local/share/octave/site/m/startup/octaverc or ~/.octaverc (both do the same thing).
So I ran set term in gnuplot shell as saw no x11 in the list.
I used homebrew to install gnuplot, so I first uninstalled it brew uninstall gnuplot, then installed with x11 using --with-x flag for that:
brew install gnuplot --with-x
This solved the issue for me.
Use brew info gnuplot to see the list of flags for gnuplot installation.
P.S.
And yes, I did download an X11 dmg and installed it using package installer, still gnuplot had no x11 in the list of supported terminals.
You can try this:
>> brew reinstall gnuplot --with-aquaterm
or
>> brew uninstall gnuplot
>> brew install gnuplot --with-aquaterm
Create a file .octaverc in your home directory and set GNUTERM to X11
echo "setenv('GNUTERM','X11')" > ~/.octaverc
Open octave terminal and type sombrero to check whether plotting works
octave:1> sombrero
This worked for me:
Unistall gnuplot
brew uninstall gnuplot
Install AquaTerm. You can download it from here: http://sourceforge.net/projects/aquaterm/
Reinstall gnuplot
brew install gnuplot
Anton is correct. You can now just reinstall gnuplot with the --with-aquaterm option. I'd upvote his answer if I had enough reputation points to do it.
$ brew uninstall gnuplot
$ brew install gnuplot --with-aquaterm
Mackuntu mentioned above that this issue has been discussed on github.
https://github.com/mxcl/homebrew/issues/14647#issuecomment-21132477
But he advised using the option --aquaterm. If you take a close look at the github link you'll see that the option is --with-aquaterm. Reinstalling gnuplot with this option today allowed me to run some old octave code that uses gnuplot for plotting graphs on OS X.
In my case, on Mas OS Mojave, the solution that worked for my was slightly different (it could be a matter of syntax only).
Following the discussion on this thread I came with the solution that worked for me - it might be important to note that it was possible for me to plot from the Octave-cli but not from Octave command line directly in terminal.
So I created a ˜/.octaverc file and added the following command to it:
setenv GNUTERM qt
Just quit the command line from octave and entered again and was able to plot.
Following thing worked for me:
setenv("GNUTERM","qt")
You can either run it on the octave cli, for local run or can set in the octave startup file for permanent.
/usr/local/octave/3.8.0/share/octave/site/m/startup/octaverc
Just remember in case you change octaverc file you have to have write permissions on it.
I have an answer that should resolve the issue you're encountering. Essentially, for me the problem was that the gnuplot build did not locate the proper AquaTerm libraries. Check out the post I made:
http://deveneezer.blogspot.com/2013/06/octave-gnuplot-and-aquaterm.html
What has worked for me is installing gnuplot-nox. Also see https://bugs.mageia.org/show_bug.cgi?id=4866
Seems like the best way to install gnuplot-nox is to install fink.
http://sourceforge.net/projects/fink/?source=dlp
fink install gnuplot-nox
seems to do a good job. However the installation was failing at one point.
So I installed gnuplot-minimal then ran gnuplot-nox install again and everything worked just fine.
fink install gnuplot-minimal
fink install gnuplot-nox
gnuplot-nox install seemed to have set aqua as the default terminal for gnuplot. Verify that by going to gnuplot shell. To verify if plotting works, type plot(1) in the shell. It should show the plot in a window.
Hope that works for you.
Like suggested in other posts, setting GNUTERM to X11 didn't solve this issue for me. Also straight installing AquaTerm for Mac OSX didn't solve this issue.
The answer is already contained in the above, but this is simpler I think:
nano ~/.octaverc
add this:
setenv("GNUTERM", "X11")
Thats it restart octave you're done.
Here is the solution that worked for me (based on different parts of the mackuntu comment)
Gnuplot is probably already installed for you by the brew install octave command, so we need to remove it first
brew uninstall gnuplot
Then aquaterm has to be installed (http://sourceforge.net/projects/aquaterm/)
After install is complete you need to install gnuplot again. This is because brew detects the presence of aquaterm during install and will not do any checks for it after.
brew install gnuplot --with-aquaterm
If you launch gnuplot after install it should show that aquaterm is supported. And all graphics in octave will work.

Resources