pypng.py problem in python 3.2

52 views
Skip to first unread message

PKHG

unread,
Jul 16, 2012, 7:41:40 AM7/16/12
to pyglet...@googlegroups.com
This
>>> struct.pack("8B", 137, 80, 78, 71, 13, 10, 26, 10)
b'\x89PNG\r\n\x1a\n'
gives an error
from line  (258 of my pypng.py)       outfile.write(struct.pack("8B", 137, 80, 78, 71, 13, 10, 26, 10))

I assume that write needs an utf-8 string but the 137 from the pack is not convertable ... to utf-8

So what should it be?



PKHG

unread,
Jul 16, 2012, 1:28:57 PM7/16/12
to pyglet...@googlegroups.com
By the way the pypng-0.0.13.tar.gz  (forgotton where I got it) is convertable for python 3.2 and all its test
run without error ;-) ... so maybe a  usable to make a working replacement ???

Op maandag 16 juli 2012 13:41:40 UTC+2 schreef PKHG het volgende:

Andreas Schiefer

unread,
Jul 16, 2012, 2:07:07 PM7/16/12
to pyglet...@googlegroups.com
It should not be converted to utf-8. PNG is a binary format and
therefore write() needs bytes (as returned by struct.pack).
Do you have a short example that produces the error? Saving a image
with the PNGImageEncoder works fine for me with Python 3.2.

I guess you are incorrectly opening the file in text mode, either by
specifying an encoding like utf-8, or you forgot to open the file in
binary mode.


Regarding the new pypng version, as far as I know it doesn't work as a
drop in replacement, because the version embedded in pyglet has some
pyglet specific changes. As pyglets version is quite old, I guess that
rebasing those changes would be quite some work.
Reply all
Reply to author
Forward
0 new messages