running imagemagick convert (console application) from python

前端 未结 1 1509
遇见更好的自我
遇见更好的自我 2021-01-07 02:52

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         


        
1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-07 03:13

    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)
    

    0 讨论(0)
提交回复
热议问题