python - Saving in memory file object with pillow -


In my designo project I have an inmemoryuploadedfile, so I open it with pillow, rotate it, and save it back in itself.

  image = request.FILES ['file'] img = Image.open (image) img = img.rotate (90) Img.save ("sample.jpeg", "jpeg") # It is true img.save (image, "jpeg") # This does not change the actual in memory image  

You will need to reset the stream state of the built-in Streamie Object that holds your uploaded file. Otherwise Image.save () will only engage at the end of the stream.

  image = request.FILES ['file'] img = Image.open  

Reset the stream state before you try to read the file again with memory May be required. (Image) img = img.rotate (90) image.seek (0) img.save (image, "jpeg") image.seek (0) image.read ()

note The uploaded file (base class of InMemoryUploadedFile) tracks the file size, and if you are changing the underlying file object, the code may be confused based on InMemoryUploadedFile.size.


Comments

Popular posts from this blog

uislider - In a MATLAB GUI, how does one implement a continuously varying slider from a GUIDE created .m file? -

Editing Python Class in Shell and SQLAlchemy -

import - Python ImportError: No module named wmi -