running imagemagick convert (console application) from python

﹥>﹥吖頭↗ 提交于 2019-12-01 01:35:38

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)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!