python-imaging/Pillow — pull request #243 by kostya0shift (2013-06-05 17:19:27+00:00)
Title: Better support for ICO files

I had some problems using current Pillow IcoImagePlugin to convert ICO images to PNG. Most images gets corrupted. I found a plugin for PIL which solves my problem:
https://code.google.com/p/casadebender/wiki/Win32IconImagePlugin

I had refactored this piece of code to work on python3 and it works just fine. But sometimes Pillow uses default IcoImagePlugin instead of this, so I had to do chmod -r IcoImagePlugin.py. Anyway, it will be better to include this plugin into Pillow to save somebody's time. Original Win32IconImagePlugin is under Apache 2.0 license. I hope there are no barriers for this.

Here is demo:
```
mkdir pillowico
cd pillowico

Y=
echo \
http://cdn.sstatic.net/stackoverflow/img/favicon.ico \
https://github.com/favicon.ico \
http://www.apple.com/favicon.ico \
http://www.microsoft.com/favicon.ico?v2 \
http://python.org/favicon.ico \
https://bits.wikimedia.org/favicon/wikipedia.ico \
https://github.com/python-imaging/Pillow/raw/master/Images/lena.ico \
'' \
| while read -d ' ' I; do Y=`expr $Y + 1`; wget $I -O s${Y}.ico; done

shift@Walley-WS:~/pillowico$ python3
Python 3.2.3 (default, Oct 19 2012, 20:10:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image
>>> from glob import glob
>>> for img in glob("s*.ico"):
... im = Image.open(img)
... im.save("n1%s.png" % img, format="PNG")
...
>>>

shift@Walley-WS:~/pillowico$ python
Python 2.7.3 (default, Aug 1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image
>>> from glob import glob
>>> for img in glob("s*.ico"):
... im = Image.open(img)
... im.save("o1%s.png" % img, format="PNG")
...
>>>

*Replace IcoImagePlugin.py*

shift@Walley-WS:~/pillowico$ python3
Python 3.2.3 (default, Oct 19 2012, 20:10:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image
>>> from glob import glob
>>> for img in glob("s*.ico"):
... im = Image.open(img)
... im.save("n2%s.png" % img, format="PNG")
...
>>>

shift@Walley-WS:~/pillowico$ python
Python 2.7.3 (default, Aug 1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image
>>> from glob import glob
>>> for img in glob("s*.ico"):
... im = Image.open(img)
... im.save("o2%s.png" % img, format="PNG")
...
>>>
```
Result:
![pilico2](https://f.cloud.github.com/assets/2418596/613428/29deec32-ce03-11e2-9a4a-7368b35a41b0.png)