eea / odfpy

API for OpenDocument in Python
GNU General Public License v2.0
311 stars 64 forks source link

photoalbum example #97

Open fusiller opened 4 years ago

fusiller commented 4 years ago

Hello, a few glitches I came across trying to run the sample with Python 3 that could be solved as follows :

from cStringIO import StringIO (no more cStringIO in Python3)

from io import BytesIO

handling JPEGs

elif (size >= 2) and (data[:2] == '\377\330'): (binary file read and byte per bate comparison)

elif (size >= 2) and (data[0] == 0o377 and data[1] == 0o330):

jpeg = StringIO(data)

    jpeg = BytesIO(data)

in the main we need to open in binary mode. If not, reading jpeg files (or any non text) will jump to except: and continue

try:
    #pictdata = open(pict_dir + "/" + picture).read()
    pictdata = open(pict_dir + "/" + picture, 'rb').read()

After doing this you should be fine. Regards Alex

PS (sorry for not being a good github user and not being able to create a pull request)