gif convert png wrong

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

gif convert png wrong

宋立新(凡卓通讯)

Hello All:

       I am writing a python tool that covert gif to png so it can be used for android ROM customization.

            My script is after the text, but it doesn’t work for some gifs, such as the one at:

 

                            ftp://help:help@222.68.182.226/gif2.gif

 

                   several frames are wrong(See png_ok and png_wrong)

 

                   And it’s not rare: 2 of my 7 gifs got wrong with the scripts.

                   While a tool named: “Ulead GIF Animator 5” under windows can convert it without problem.

                  

                   To be honest, imagemagick and another linux tool gif2png also has the same problem. And Also AcdSee (Under Windows)!

                   I have no idea about this and I really wish to write a tool to improve our efficiency.

                   Could some expert take a look on it?

         BR,

Lixin Song

=======================================================================

#!/usr/bin/env python

# -*- coding: utf-8 -*-

 

import Image

 

im = Image.open('gif2.gif')

 

def iter_frames(im):

    try:

        i= 0

        while 1:

            im.seek(i)

            imframe = im.copy()

            if i == 0:

                palette = imframe.getpalette()

            else:

                imframe.putpalette(palette)

            yield imframe

            i += 1

    except EOFError:

        pass

 

for i, frame in enumerate(iter_frames(im)):

    frame.save('test%d.png' % i,**frame.info)

 


_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig
Reply | Threaded
Open this post in threaded view
|

Re: gif convert png wrong

Charlie Clark-6
Dear Song (I hope I have this the right way round),


Am 20.12.2011, 03:50 Uhr, schrieb 宋立新(凡卓通讯)
<[hidden email]>:

> Hello All:
>       I am writing a python tool that covert gif to png so it can be used
> for android ROM customization.
>            My script is after the text, but it doesn’t work for some  
> gifs,
> such as the one at:
>                            ftp://help:help@222.68.182.226/gif2.gif
>                   several frames are wrong(See png_ok and png_wrong)
>                   And it’s not rare: 2 of my 7 gifs got wrong with the
> scripts.
>                   While a tool named: “Ulead GIF Animator 5” under
> windows can convert it without problem.
>                   To be honest, imagemagick and another linux tool  
> gif2png
> also has the same problem. And Also AcdSee (Under Windows)!
>                   I have no idea about this and I really wish to write a
> tool to improve our efficiency.
>                   Could some expert take a look on it?
>         BR,
> Lixin Song

The problem seems to be related to the underlying library used for either
GIF or PNG images as your script runs fine on my machine (Mac OS 10.7).
Frames 2 and 56 look a bit weird but the original image looks like this.
I'm not sure which frames you think don't work.

FWIW your script isn't very Pythonic (the try clause should preferably
only contain one statement with known error conditions) and can be
rewritten thus:

for i in range(im.info['duration']):
       try:
           im.seek(i)
       except EOFError:
           break
       im.save("test%02d.png" % i)

Charlie
--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Kronenstr. 27a
Düsseldorf
D- 40217
Tel: +49-211-600-3657
Mobile: +49-178-782-6226
_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig
Reply | Threaded
Open this post in threaded view
|

答复: gif convert png wrong

宋立新(凡卓通讯)
Dear Charlie:
        For my case, frame 57 is wrong and also some after 57.
        I think it's a known issue bcz so many tools(Include ACDSee) got same problem. Maybe IP reasons.
        I will try on MacOS.
        Also thanks for your advice to be more Pythinic. :P

        Br,
        Lixin Song

-----邮件原件-----
发件人: image-sig-bounces+songlixin=[hidden email] [mailto:image-sig-bounces+songlixin=[hidden email]] 代表 Charlie Clark
发送时间: 2011年12月30日 星期五 4:49
收件人: [hidden email]
主题: Re: [Image-SIG] gif convert png wrong

Dear Song (I hope I have this the right way round),


Am 20.12.2011, 03:50 Uhr, schrieb 宋立新(凡卓通讯)
<[hidden email]>:

> Hello All:
>       I am writing a python tool that covert gif to png so it can be used
> for android ROM customization.
>            My script is after the text, but it doesn’t work for some  
> gifs,
> such as the one at:
>                            ftp://help:help@222.68.182.226/gif2.gif
>                   several frames are wrong(See png_ok and png_wrong)
>                   And it’s not rare: 2 of my 7 gifs got wrong with the
> scripts.
>                   While a tool named: “Ulead GIF Animator 5” under
> windows can convert it without problem.
>                   To be honest, imagemagick and another linux tool  
> gif2png
> also has the same problem. And Also AcdSee (Under Windows)!
>                   I have no idea about this and I really wish to write a
> tool to improve our efficiency.
>                   Could some expert take a look on it?
>         BR,
> Lixin Song

The problem seems to be related to the underlying library used for either
GIF or PNG images as your script runs fine on my machine (Mac OS 10.7).
Frames 2 and 56 look a bit weird but the original image looks like this.
I'm not sure which frames you think don't work.

FWIW your script isn't very Pythonic (the try clause should preferably
only contain one statement with known error conditions) and can be
rewritten thus:

for i in range(im.info['duration']):
       try:
           im.seek(i)
       except EOFError:
           break
       im.save("test%02d.png" % i)

Charlie
--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Kronenstr. 27a
Düsseldorf
D- 40217
Tel: +49-211-600-3657
Mobile: +49-178-782-6226
_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig

_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig
Reply | Threaded
Open this post in threaded view
|

Re: 答复: gif convert png wrong

Charlie Clark-6
Hi Song,

Am 30.12.2011, 02:38 Uhr, schrieb 宋立新(凡卓通讯)  
<[hidden email]>:

> Dear Charlie:
> For my case, frame 57 is wrong and also some after 57.
> I think it's a known issue bcz so many tools(Include ACDSee) got same  
> problem. Maybe IP reasons.

Possibly a palette problem. If I open the file in Photoline (a very good  
Photoshop clone) I have two layers that have no background while all  
others have a black background. This would seem to be a palette  
optimisation.

If you compile your own version of PIL be sure to check the versions of  
the underlying libraries.

> I will try on MacOS.

> Also thanks for your advice to be more Pythinic.

Of course, your use of an generator function was Pythonic but a little  
over the top, especially as it actually creates a counter that the for  
loop could use. The counter is necessary as my use of "duration" was an  
incorrect guess!

More importantly, you are unnecessarily creating copies of each frame in  
memory just to save the frames to disk. However, as disk IO seems to be  
the bottleneck this has little practical implications for this image but  
could be important in another situation.

Charlie
--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Kronenstr. 27a
Düsseldorf
D- 40217
Tel: +49-211-600-3657
Mobile: +49-178-782-6226
_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig