【发布时间】:2013-09-11 19:13:13
【问题描述】:
在我的 django 服务器上,我通过命令行使用 imagemagick 创建了一个图像文件。
cmd = local_file + " -crop 50%x50%+10+10 " + temp_final_file
out, err = subprocess.Popen( cmd.split(),
stdin = subprocess.PIPE,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE ).communicate()
然后我将文件返回给客户端:
mt = mimetypes.guess_type( temp_final_file )[0]
with open( temp_final_file, "rb" ) as f:
response = HttpResponse( f.read(), mimetype=mt )
return response
我想知道是否可以避免写入本地文件而直接返回字节?
【问题讨论】:
-
python 模块 StringIO docs.python.org/2/library/stringio.html 可能对你有用。
-
注意:crop 命令只是一个例子。通过 imagemagick 运行更复杂的命令。
标签: python django imagemagick