I am trying to rasterize some fonts using imagemagick with this command which works fine from a terminal:
convert -size 30x40 xc:white -fill white -fill bla
I figured it out: It turns out that windows has its own convert.exe
program in PATH
.
The following code prints b'C:\\Windows\\System32\\convert.exe\r\n'
:
try:
print(subprocess.check_output(["where",'convert'],stderr=subprocess.STDOUT,shell=True))
except CalledProcessError as e:
print(e)
print(e.output)
Running the same code in a terminal shows that imagemagick's convert
shadows Windows' convert
:
C:\Users\Navin>where convert
C:\Program Files\ImageMagick-6.8.3-Q16\convert.exe
C:\Windows\System32\convert.exe
.
I did not restart python after installing ImageMagick so its PATH
still pointed to the Windows version.
Using the full path works:
try:
cmd= ['C:\Program Files\ImageMagick-6.8.3-Q16\convert','-size','30x40','xc:white','-fill','white','-fill','black','-font','fonts\Helvetica Regular.ttf','-pointsize','40','-gravity','South','-draw',"text 0,0 'P'",'draw_text.gif']
print(str.join(' ', cmd))
print('stdout: {}'.format(subprocess.check_output(cmd,shell=True,stderr=subprocess.STDOUT)))
except CalledProcessError as e:
print(e)
print(e.output)