In some tutorials was explained to use StringIO
in Pillow save method. but when I use this testcode:
from PIL import Image
from io import StringIO, BytesIO
photo = Photo.objects.get(pk=1)
bytes = BytesIO()
string = StringIO()
image = Image.open(photo.image)
image.save(string, 'PNG')
then I get the error:
string argument expected, got 'bytes'
But when I use BytesIO
like this:
image.save(bytes, 'PNG')
it works fine. That is strange, because the error message says that a string is expected and bytes is wrong, but obviously the opposite is correct. And that is also contrary to the informations I got while checking tutorials.
Maybe the behavior of save()
was changed in the Pillow fork, and the error message was not updated? Or is it different because I use Python 3 with io
module instead of StringIO
module?
edit, examples where StringIO
is proposed