Calling Command Line ImageMagick from Python 3.6 Subprocess Module

Announcements pertaining to ImageMagick, or ImageMagick related software. This list is moderated. No discussions here, instead post to the users group instead.
Post Reply
User avatar
fmw42
Posts: 22109
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Calling Command Line ImageMagick from Python 3.6 Subprocess Module

Post by fmw42 » 2017-10-27T15:29:21-07:00

I have just now played around with subprocess module in Python using ImageMagick 6.9.9.20 Q16 Mac OSX Sierra. Both of the following work for me. See http://www.bogotobogo.com/python/python ... module.php

These are the two scripts (on my desktop)

subprocess_convert1.py

Code: Select all

#!/opt/local/bin/python3.6

import subprocess

cmd = ['/usr/local/bin/convert','-size','30x40','xc:white','-fill','white','-fill','black','-font','Arial','-pointsize','40','-gravity','South','-draw',"text 0,0 'P'",'/Users/fred/desktop/draw_text1.gif']

subprocess.call(cmd, shell=False)

subprocess_convert2.py

Code: Select all

#!/opt/local/bin/python3.6

import subprocess

cmd = '/usr/local/bin/convert -size 30x40 xc:white -fill white -fill black -font Arial -pointsize 40 -gravity South -draw "text 0,0 \'P\'" /Users/fred/desktop/draw_text2.gif'

subprocess.call(cmd, shell=True)
They are called in a bash shell terminal with:

Code: Select all

python3.6 subprocess_convert1.py

or

python3.6 subprocess_convert2.py
They both result in

Image

Post Reply