[Image-SIG] Small addition to the IcoImagePlugin.

Blake Winton blake at phantomfiber.com
Mon Feb 26 18:00:41 CET 2007

I've been using PIL to verify some images, and one of the things I
wanted to verify was that icon files contained a certain number of sizes
in specific bit-depths.  The included IcoImagePlugin only reads out the
information for the largest bit depth, which wasn't so useful for me, so
I added the following two lines, which set the info['bmp_sizes'] to a
list of tuples of (width, height, bitdepth).

Anyways, I thought someone else out there might find it useful, so here
it is.


Diff follows:
*** IcoImagePlugin.py.orig      Mon Feb 26 11:51:06 2007
--- IcoImagePlugin.py   Mon Feb 26 11:27:43 2007
*** 54,65 ****
--- 54,67 ----

          # pick the largest icon in the file
          m = ""
+         self.info['bmp_sizes'] = []
          for i in range(i16(s[4:])):
              s = self.fp.read(16)
              if not m:
                  m = s
              elif ord(s[0]) > ord(m[0]) and ord(s[1]) > ord(m[1]):
                  m = s
+             self.info['bmp_sizes'].append( (ord(s[0]), ord(s[1]),
              #print "width", ord(s[0])
              #print "height", ord(s[1])
              #print "colors", ord(s[2])

More information about the Image-SIG mailing list