samedi 18 avril 2015

How to convert PIL image file into string in python3.4?

I have been trying to read a jpeg file using PIL in python 3.4. I need to save this file into string format. Although some options are provided on this side but I have tried a few but it is not working. Following is my code snippet which i have found on this site only:-



from io import StringIO

fp = Image.open("images/login.jpg")
output = StringIO()
fp.save(output, format="JPEG")
contents = output.getvalue()
output.close()


But i am facing the following error :-


TypeError: string argument expected, got 'bytes'


Could you please suggest what I have done wrong and how to get this working?


Aucun commentaire:

Enregistrer un commentaire