无法通过 Shell 命令 (PHP) 保存 PIL 图像

Can't Save PIL Image From Shell Command (PHP)

我有一个非常简单的 python 脚本,它可以创建图像、写入一些文本,最后输出到文件。 运行 来自终端的脚本通过 ssh 工作正常并按预期输出图像。但是,如果我尝试通过 php 运行 命令,一切正常,直到我 运行 img.save() 函数。

我正在写入的文件夹具有全局写入权限,所以我不确定挂断可能是什么。

建议?

PYTHON:

from PIL import Image
background = Image.new('RGB', (50, 50), 'black')
print 'img created'
background.save('test.png')
print 'img saved'

PHP:

$execStr = "python imgScript.py";
exec($execStr,$output,$message);
print_r($output);
//output// Array ( [0] => img created )

尽量使用绝对路径。像这样:

background.save('/path/to/test/test.png')

甚至这样:

import os
background.save(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test.png'))

这会将文件保存在与脚本相同的目录中