3
votes

Trying to use a subprocess call in a python script to run an Imagemagick command. I installed imagemagick in /usr/local/Cellar, so I tried two options since it looked like it wasn't finding the convert command.

By the way, the 'convert' command is an imagemagick one. :) Here is the part of my code that directly relates to it.

import sys, os, subprocess, string
tempo = 8; #this is just for sample purposes, in the actual code this variable is imported from a csv file

# test with just captioning one image and not whole loop
subprocess.call('convert rgb10.png -pointsize 50 -draw "text 180,180 ' + str(tempo) + '" rgb10-n.png')

I've also tried "subprocess.call('/usr/local/Cellar/imagemagick/6.8.9-8/bin/c...." since I thought it maybe wasn't finding the command.

Also, I when I run this command in my terminal command line (not in a script), it works (ex: convert rgb298.png -pointsize 50 -draw "text 180,180 'test' " rgb298-n.png) so I know it must be an issue with my subprocess call.

This is the error I receive when I run it:

   subprocess.call('/usr/local/Cellar/imagemagick/6.8.9-8/bin/convert rgb10.png -pointsize 50 -draw "text 180,180 ' + str(tempo[9]) + '" rgb10-n.png')
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 470, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 623, in __init__
    errread, errwrite)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 1141, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

NOTE: I also tried subprocess.call('python2.6 convert rgb10.png ...

1

1 Answers

3
votes

... And I've gotten it to work, it was silly!

Added , shell=True

subprocess.call('convert rgb10.png -pointsize 50 -draw "text 180,180 ' + str(tempo) + '" rgb10-n.png', shell=True)

and it works now for anyone else running into this issue.

Except it's NOT actually drawing or taking into the account the variable 'tempo', aka not processing the + str(tempo) + bit