[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] pygame.image.save()
FYI, the bug in 1.8.0release also meant that saving as .JPG saved as
.tga - having the test try out both all caps and all lower would be
good.
On Mon, Apr 14, 2008 at 8:47 PM, René Dudfield <renesd@xxxxxxxxx> wrote:
> ah, oops.
>
> Now that test_magic is fixed, the saving test fails in the pygame
> 1.8.0release version(png saved as jpg only, other formats work)... but
> passes in svn.
>
> cheers,
>
>
>
>
> On Tue, Apr 15, 2008 at 1:09 PM, Lenard Lindstrom <len-l@xxxxxxxxx> wrote:
> > This works better. The other keeps returning 1:
> >
> >
> > def test_magic(f, magic_hex):
> > """ tests a given file to see if the magic hex matches.
> > """
> > data = f.read(len(magic_hex))
> >
> > if len(data) != len(magic_hex):
> > return 0
> >
> > for i in range(len(magic_hex)):
> > if magic_hex[i] != ord(data[i]):
> > return 0
> >
> > return 1
> >
> >
> > And Pygame in SVN is now creating PNG images for me.
> >
> > Lenard
> >
> >
> >
> >
> > René Dudfield wrote:
> >
> > > Good point about pygame.image.load not caring about file extensions,
> > > and only file contents...
> > >
> > > I just updated the unittest to check the magic hex numbers of the file
> > > to test if the file is actually getting saved how we want it to be.
> > >
> > > Below is the magic testing function I used - in case you want to use it.
> > >
> > > cheers,
> > >
> > >
> > >
> > > def test_magic(f, magic_hex):
> > > """ tests a given file to see if the magic hex matches.
> > > """
> > > data = f.read(len(magic_hex))
> > >
> > > if len(data) != len(magic_hex):
> > > return 0
> > >
> > > for i in range(len(magic_hex)):
> > > if data[i] != data[i]:
> > > return 0
> > >
> > > return 1
> > >
> > >
> > > magic_hex = {}
> > > magic_hex['jpg'] = [0xff, 0xd8, 0xff, 0xe0]
> > > magic_hex['png'] = [0x89 ,0x50 ,0x4e ,0x47]
> > > magic_hex['tga'] = [0x0, 0x0, 0xa]
> > > magic_hex['bmp'] = [0x42, 0x4d]
> > >
> > > if test_magic(open(temp_filename, "rb"), magic_hex["png"]):
> > > print "this is a png file!"
> > >
> > >
> > >
> > >
> > > On Tue, Apr 15, 2008 at 10:56 AM, Lenard Lindstrom <len-l@xxxxxxxxx>
> > wrote:
> > >
> > >
> > > > Ian Mallett wrote:
> > > >
> > > >
> > > >
> > > > > Well, it worked for me--saving it to a valid .png file.
> > > > >
> > > > >
> > > > >
> > > > Are you sure? I just tried it with a .png picture. It was certainly not
> > > > saved as a PNG image. Changing the file extension to .jpg let me view it
> > > > with ImageNavigator. The reason this bug may have slipped through is
> > that
> > > > Pygame apparently ignores the file extension when determining file type.
> > It
> > > > will quite happily load a JPEG named "something.png", or even
> > "something".
> > > >
> > > >
> > > >
> > >
> >
> >
>