jbaiter / jpegtran-cffi

Fast, (mostly) lossless JPEG transformations with Python
http://jpegtran-cffi.readthedocs.org
MIT License
145 stars 23 forks source link

Python3.4: transform.py: JPEGImage.save() fails with TypeError on fp.write() #10

Closed LandingEllipse closed 10 years ago

LandingEllipse commented 10 years ago

Under Python3.4, calling .save() on an JPEGImage object raises the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.4/site-packages/jpegtran/transform.py", line 221, in save
    fp.write(self.data)
TypeError: must be str, not bytearray

In transform.py line 220 we see that the file is opened in regular string mode (w) as opposed to binary mode (wb) which is required to write bytearrays.

Workaround: change transform.py line 220 from:

        with open(fname, 'w') as fp:

to:

        with open(fname, 'wb') as fp:
jbaiter commented 10 years ago

Thank you! :+1: