【问题标题】:Python, Imagemagick, and subprocess callPython、Imagemagick 和子进程调用
【发布时间】:2016-03-02 14:13:03
【问题描述】:

尝试在 python 脚本中使用子进程调用来运行 Imagemagick 命令。 我在 /usr/local/Cellar 中安装了 imagemagick,所以我尝试了两个选项,因为它看起来好像没有找到转换命令。

顺便说一句,'convert' 命令是一个 imagemagick 命令。 :) 这是我的代码中与它直接相关的部分。

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')

我也试过 "subprocess.call('/usr/local/Cellar/imagemagick/6.8.9-8/bin/c...." 因为我认为它可能是'找不到命令。

另外,我当我在终端命令行(而不是脚本)中运行此命令时,它可以工作(ex: convert rgb298.png -pointsize 50 -draw "text 180,180 'test' " rgb298-n.png),所以我知道这一定是我的子进程调用的问题。 p>

这是我在运行它时收到的错误

   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

注意:我也试过 subprocess.call('python2.6 convert rgb10.png ...

【问题讨论】:

    标签: python imagemagick subprocess


    【解决方案1】:

    ...我已经让它工作了,这很愚蠢!

    已添加,shell=True

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

    它现在适用于遇到此问题的任何其他人。

    除了它实际上没有绘制或考虑变量“tempo”,也就是不处理 + str(tempo) + bit

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-02
      • 1970-01-01
      • 2019-02-20
      • 1970-01-01
      • 1970-01-01
      • 2017-10-08
      • 1970-01-01
      • 2015-07-18
      相关资源
      最近更新 更多