【问题标题】:Getting image as output from php script calling it using python从使用python调用它的php脚本获取图像作为输出
【发布时间】:2017-05-18 05:58:51
【问题描述】:

我在这里尝试使用 php 脚本 textcleaner 处理图像。我必须在我的 python 项目的其他部分运行这个 php 脚本。我对从 php 脚本 textcleaner 获取输出图像感到困惑(我从这里得到这个脚本:

http://www.fmwconcepts.com/imagemagick/textcleaner/index.php )

我在 python 中运行它的代码是 ..

import subprocess
proc = subprocess.Popen("php textcleaner.php  -g -e none -f 10 -o 5   src.jpg out.jpg", shell=True, stdout=subprocess.PIPE)
script_response = proc.stdout.read()

这里 textcleaner.php 是 php 脚本文件,然后是 (-g -e none -f 10 -o 5) 是我想传递给脚本(textcleaner)以处理我的图像(src.jpg)的参数,输出图像应该是out.jpg

如果有人以前使用过这个或知道如何将输出作为图像输出到 out.jpg 中,请告诉我。

我还使用 print() 检查了 script_response,但它给了我 textcleaner 的帮助菜单。

【问题讨论】:

  • 您的第一个错误是 bash 脚本而不是 php 代码。
  • 你能告诉我如何在我的python程序中执行它

标签: php python


【解决方案1】:

这个答案Running bash script from within python 可能会为您指明正确的方向 - 我不使用 Python 或 bash,因此无法进一步提供帮助。

import subprocess
print "start"
subprocess.call("textcleaner -g -e none -f 10 -o 5 src.jpg out.jpg")
print "end"

不要忘记使 textcleaner 可执行,例如 777 或 755 可以工作。我会将 textcleaner 重命名为 textcleaner.sh 并在您的代码中使用 textcleaner.sh。它只是提醒您文件类型是什么。

【讨论】:

  • 感谢您的热心帮助
猜你喜欢
  • 2012-02-01
  • 1970-01-01
  • 2011-08-11
  • 2014-08-31
  • 2011-11-16
  • 1970-01-01
  • 2017-05-01
  • 2013-06-03
  • 1970-01-01
相关资源
最近更新 更多