[Answered ]-Return dynamic generated file without creating tmp version?

2👍

ImageMagick can write to its stdout, so you don’t actually need the temporary file. Try this:

cmd = ['convert', local_file, '-crop', '50%x50%+10+10', '-']
new_image = subprocess.check_output( cmd )
response = HttpResponse( new_image, mimetype=mt )

Note: you still have to figure out the mime type. Without a file, that might be more difficult.

👤Robᵩ

0👍

f.read() is just a python2 string of bytes. You can pass anything there.

You would have to use some interface than allows you to retrieve directly bytes, rather than write to a file. For example, an imagemagick wrapper, like this:

https://www.assembla.com/wiki/show/pythonmagickwand

👤Zah

Leave a comment