A few months ago I wrote a piece on image manipulation in FileMaker container fields on Mac OS X. That type of manipulation was relatively simple – rotating an image – but required AppleScript and ImageEvents. What if you required a more complex adjustment of images, such as converting from TIFF to JPEG, or compression, blurring, re-sizing?
Image Events actually does some of these types of manipulation, but not always with expected results. Many people turn to Photoshop for these effects. You can also write AppleScripts to interact with Photoshop and FileMaker, but may end up dealing with syntax changes or application version changes. Photoshop also must be open and active, and is expensive.
Another option we looked into was ImageMagick, a powerful and free open source command line tool that also will work with multiple programming language like PHP, Perl, Ruby and others.
Installing ImageMagick on the Mac requires time and patience. Apparently the people who support this (free, by the way) software only maintain the latest OS-compatible version as an executable installer – meaning Mac OS Lion. The machines that would run this were still on Snow Leopard, so this required a more manual method.
The Mac OS X binary release requires MacPorts, which in turn requires XCode. These first must be installed and configured correctly. MacPorts, once installed, also required a self-update (sudo port -v selfupdate), which in our instance required tweaking rsync settings due to firewall issues. Alas, this step is poorly documented, but in our instance we changed this document: /opt/local/etc/macports/source.conf
By commenting out the last line, which uses rsync, and adding a direct url, we were able to get MacPorts to update properly.
# rsync://rsync.macports.org/release/tarballs/ports.tar [default] http://www.macports.org/files/ports.tar.gz [default]
Then in the Terminal, we typed the following. Then we sat back and enjoyed many minutes of peace while ImageMagick installed, as this took a while.
sudo port -d sync
Finally, installing ImageMagick itself was a one line command in the Terminal:
sudo port install ImageMagick
Once installed, you can test ImageMagick by running “convert-version” in the Terminal. If properly installed, you will get something like the following:
"Version: ImageMagick 6.7.2-0 2011-09-20 Q16 http://www.imagemagick.org Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC Features: OpenMP OpenCL"
Integration with FileMaker
Since it now worked in the Terminal, it was time to turn our attention to integration with FileMaker. For this to work we needed to execute a shell statement from FileMaker. As this solution already used Troi File, which has a function to execute shell, we just needed our command. Troi File’s command TrFile_ExecuteShell( ) is used to send commands to ImageMagick. Prior to each shell action we built the command in a variable, which let us debug this in the Data Viewer.
To complicate matters, certain ImageMagick actions returned values, while others returned nothing. For example, the version command returned the string inside the execution step, so setting a variable to TrFile_ExecuteShell populated this variable with the result. This was a perfect way to test whether or not to continue, since computers without ImageMagick installed would not be able to perform anything, and we could exit gracefully if the version command did not contain any ImageMagick information.
There are several commands that we can send to ImageMagick. Each command accepts different arguments. For example, “identify” provides information about the image, while “convert” performs the actual conversions. The shell command string requires the full path to the command, which usually is inside the “/opt/local/bin/” folder.
Our primary requirement was to convert an image from one type to another, filtering and resizing the image to certain specifications. The beauty of ImageMagick and shell scripting is that you can point to a source image across the network and send the converted file to another location across the network.
The convert command uses certain parameters such as source file, resize and resize value, and where to write the file. An example of this with some fill-in-the-blank naming appears below.
"/opt/local/bin/convert path_to_source/filename.TIF -set option:filter:blur 0.8 -resize %RESIZE_VALUE% -strip -quality 90 -write \"path_to_destination/filename.jpg\" +delete"
Alas, this command returns nothing from within FileMaker. There is no way to know whether or not the conversion was successful, aside from a second command using Troi File to see if the new file exists.
While there are significant cost and overhead advantages to using ImageMagick over, for example, Photoshop, there is a corresponding cost in terms of time and effort. The command line doesn’t always invite users to have a great experience.
While I have not tested these features, Monkeybread Software’s plugin for FileMaker comes with image editing using GraphicsMagick, a fork from ImageMagick a few years back. Other plugins provide execute shell commands, so you’re not just limited to Troi File.
Trapping for errors remains important, as sometimes you get feedback, and sometimes nothing, from within FileMaker. Usually you can copy the command from the Data Viewer into the Terminal, and then you will get some feedback about any errors. That said, this is a powerful method to integrate image manipulation into FileMaker.