Calling ImageMagick from script (convert -draw 'text...)

Hi everybody - I’m new here and pretty new to AppleScript. What a wonderful recourse, this site is.

To my problem then:

I’m writing a script to generate some images with text on them. They’re to be used as leading frames in videos of experiments, detailing the experiment at hand.

The script uses AppleScript and Finder to build a shell command to get ImageMagick to produce the desired first frame.

The piece generating the command is here:

set shellCommand to "/usr/local/bin/convert  -size 1920x1080 xc: -font Helvetica -fill black -pointsize " & titleFontSize & " -draw 'text " & titleXInsert & "," & titleYInsert & " \"" & titleStr & "\"' " & quoted form of (origFolderPath & "testFP1.jpg")

The result of that is this:

do shell script "/usr/local/bin/convert  -size 1920x1080 xc: -font Helvetica -fill black -pointsize 60 -draw 'text 250,250 \"Forth Replacement Crossing\"' '/Volumes/HDD/Movies/Video Recordings FRC/Buffering induced vibrations, CSB/Annex C1 - Configuration 1/testFP1.jpg'"

It executes fine, and testFP1.jpg is created in the desired path. However, the image is just the blank canvas - no text.

Pasting the resulting shellCommand (removing ) directly into Terminal, does produce the image with text in the desired position. I think convert gives a clue here. Besides the testFP1.jpg , I also get this message in Terminal:

If I in Terminal perform the same command but without the /usr/local/bin/ I still get the image with text, but no message. But using this in the script doesn’t find the convert programme. (I got the /usr/local/bin/ from here:

I also tried doing a different command instead of text placing another image in the canvas (using -composite), and the result there was as expected.
Thus inspired I tried using -annotate instead which still produced no text when called from the Apple script.

So - I’m thinking maybe the problem is related to looking up fonts - maybe. Or from some reading I did (elsewhere that I can’t recall) maybe related to Ghost Script not being found.
I don’t know how to test if these are the issues, or what to do about it.
Can someone help me on this?

Thanks a lot in advance!


Well, I still don’t know why it sort of works (the command convert is found), but running shell scripts from AppleScript is detailed here:

Theres several good-to-know bits on that page, but what I needed to solve my problem was this:

Just to bend it in neon:
I got the full path of the command ‘convert’ by typing:
which convert
in Terminal.
→ /opt/local/bin/convert

Then use this in the beginning of my shellCommand, like so:

set shellCommand to "/opt/local/bin/convert  -size 1920x1080 xc: -font Helvetica -fill black -pointsize " & titleFontSize & " -draw 'text " & titleXInsert & "," & titleYInsert & " \"" & titleStr & "\"' " & quoted form of (origFolderPath & "testFP1.jpg")

Something just dawned on me as a likely explanation to anyone interested.

I think I read somewhere that ImageMagick is often included with distributions of UNIX-systems. So I’m thinking probably an older version of convert is also located in the default search path.
This would also explain why before the change to include “/opt/local/bin/”, the “canvas:” option was not found - I read somewhere else, that the “canvas:” was introduced quite recently to do the same as “xc:” while being more intuitive.