5

I'm working with images2gif and getting this error. Any ideas?

UnicodeDecodeError: 'ascii' codec can't decode byte 0x87 in position 10: ordinal not in range(128)

Test file:

from PIL import Image
from images2gif import writeGif

FRAMES = 2
FRAME_DELAY = 0.75
WIDTH, HEIGHT = 600, 600

frames = []
img1 = Image.open('1.jpg')
img2 = Image.open('2.jpg')
frames.append(img1)
frames.append(img2)

writeGif("test.gif", frames, duration=FRAME_DELAY, dither=0)

Traceback:

Traceback (most recent call last):
  File "gif.py", line 15, in <module>
    writeGif("topmovie.gif", frames, duration=FRAME_DELAY, dither=0)
  File "/Users/Craig/Documents/github/RTB/images2gif.py", line 575, in writeGif
    gifWriter.writeGifToFile(fp, images, duration, loops, xy, dispose)
  File "/Users/Craig/Documents/github/RTB/images2gif.py", line 435, in writeGifToFile
    fp.write(header.encode('utf-8'))

images2gif line 435: fp.write(header.encode('utf-8'))

Updated traceback:

Traceback (most recent call last):
  File "gif.py", line 16, in <module>
    writeGif("test.gif", frames, duration=FRAME_DELAY, dither=0)
  File "/Users/Craig/Documents/github/RTB/images2gif.py", line 579, in writeGif
    gifWriter.writeGifToFile(fp, images, duration, loops, xy, dispose)
  File "/Users/Craig/Documents/github/RTB/images2gif.py", line 440, in writeGifToFile
    fp.write(globalPalette)
TypeError: must be string or buffer, not None
Craig Cannon
  • 1,449
  • 2
  • 13
  • 20
  • 1
    Which python version are you on? – aIKid Dec 13 '13 at 22:11
  • Which version of images2gif you are using? I can't see that line in last version – PasteBT Dec 13 '13 at 22:17
  • 1
    this version has no encode within and seems more reasonable to me https://github.com/luopio/bag-of-tricks/blob/master/python/images2gif.py; can't guess why one can encode a string; code of image2gif do not look like py3 friendly, so I guess it's written for py2 – alko Dec 13 '13 at 22:17
  • 4
    Comment: use `Pillow` instead of `PIL` which is nearly a dead project: https://pypi.python.org/pypi/Pillow/ – Laurent LAPORTE Dec 13 '13 at 22:19
  • @alkid 2.7.5. thanks alko + laurent-laporte. I updated and now am getting a separate error re: palettes. I'll add it to my question. – Craig Cannon Dec 14 '13 at 00:33
  • Hmm -- on your original question: U+0087 is a *control* character, which cannot be converted to plain ASCII (hence (probably) the not-in-range error). It should not have been there in your input, or the encoding was not "ASCII" but something else. Most likely Windows-1252 -- the "dagger". – Jongware Dec 14 '13 at 01:19
  • @CraigCannon it seems the [latest version available on pypi (1.0.1)](https://pypi.python.org/pypi/images2gif) is newer than the one provided above (by @alko), also the [linked bitbucket repo](https://bitbucket.org/bench/images2gif.py/overview) is even newer (10/2013) which probably means it has some bugfix/feature commits in there. Please try upgrading and running your code again. Also, you could submit your issue to the bitbucket repo together with your source image. – tutuDajuju Feb 15 '14 at 11:46

1 Answers1

2

Your updated question is also here: Error in images2gif.py with GlobalPalette

It references an issue on images2gif in which the author says they're going to rewrite the module to not use PIL/Pillow, but are busy: https://code.google.com/p/visvis/issues/detail?id=81

That in turn references a patched images2gif that is claimed to fix the issue: https://github.com/rec/echomesh/blob/master/code/python/external/images2gif.py

Community
  • 1
  • 1
Jason S
  • 13,538
  • 2
  • 37
  • 42