[Checkins] SVN: zope.app.file/trunk/src/zope/app/file/ Teach zope.app.file.image.getImageInfo about Windows BMP files.

Marius Gedminas marius at pov.lt
Thu Jun 14 09:39:37 EDT 2007


Log message for revision 76693:
  Teach zope.app.file.image.getImageInfo about Windows BMP files.
  
  

Changed:
  U   zope.app.file/trunk/src/zope/app/file/image.py
  U   zope.app.file/trunk/src/zope/app/file/tests/test_image.py

-=-
Modified: zope.app.file/trunk/src/zope/app/file/image.py
===================================================================
--- zope.app.file/trunk/src/zope/app/file/image.py	2007-06-14 11:10:59 UTC (rev 76692)
+++ zope.app.file/trunk/src/zope/app/file/image.py	2007-06-14 13:39:36 UTC (rev 76693)
@@ -152,5 +152,11 @@
         except ValueError:
             pass
 
+    # handle BMPs
+    elif (size >= 30) and data.startswith('BM'):
+        kind = struct.unpack("<H", data[14:16])[0]
+        if kind == 40: # Windows 3.x bitmap
+            content_type = 'image/x-ms-bmp'
+            width, height = struct.unpack("<LL", data[18:26])
 
     return content_type, width, height

Modified: zope.app.file/trunk/src/zope/app/file/tests/test_image.py
===================================================================
--- zope.app.file/trunk/src/zope/app/file/tests/test_image.py	2007-06-14 11:10:59 UTC (rev 76692)
+++ zope.app.file/trunk/src/zope/app/file/tests/test_image.py	2007-06-14 13:39:36 UTC (rev 76693)
@@ -160,6 +160,18 @@
         from zope.app.file.image import getImageInfo
         t, w, h = getImageInfo("\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff\xdb\x00C")
 
+    def test_getImageInfo_bmp(self):
+        from zope.app.file.image import getImageInfo
+        t, w, h = getImageInfo('BMl\x05\x00\x00\x00\x00\x00\x006\x04\x00\x00('
+                               '\x00\x00\x00\x10\x00\x00\x00\x10\x00\x00\x00'
+                               '\x01\x00\x08\x00\x01\x00\x00\x006\x01\x00\x00'
+                               '\x12\x0b\x00\x00\x12\x0b\x00\x00\x00\x01\x00'
+                               '... and so on ...')
+        self.assertEqual(t, "image/x-ms-bmp")
+        self.assertEqual(w, 16)
+        self.assertEqual(h, 16)
+
+
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(TestImage),



More information about the Checkins mailing list