[Zope3-checkins] SVN: Zope3/branches/3.3/ Teach zope.app.file.image.getImageInfo about Windows BMP files.

Marius Gedminas marius at pov.lt
Thu Jun 14 10:02:00 EDT 2007


Log message for revision 76699:
  Teach zope.app.file.image.getImageInfo about Windows BMP files.
  
  Merged revision 76693 from trunk with
  
    svn merge -r 76692:76693 svn://svn.zope.org/repos/main/zope.app.file/trunk/src/zope/app/file
  
  

Changed:
  U   Zope3/branches/3.3/doc/CHANGES.txt
  U   Zope3/branches/3.3/src/zope/app/file/image.py
  U   Zope3/branches/3.3/src/zope/app/file/tests/test_image.py

-=-
Modified: Zope3/branches/3.3/doc/CHANGES.txt
===================================================================
--- Zope3/branches/3.3/doc/CHANGES.txt	2007-06-14 13:57:46 UTC (rev 76698)
+++ Zope3/branches/3.3/doc/CHANGES.txt	2007-06-14 14:02:00 UTC (rev 76699)
@@ -10,6 +10,8 @@
 
     Bugfixes
 
+      - zope.app.file.image couldn't recognize Windows BMP files.
+
       - #98111: z.a.form.browser.itemswidget.MultiDataHelper._toFieldValue()
         context._type attribute was being ignored when the result was an empty
         collection.

Modified: Zope3/branches/3.3/src/zope/app/file/image.py
===================================================================
--- Zope3/branches/3.3/src/zope/app/file/image.py	2007-06-14 13:57:46 UTC (rev 76698)
+++ Zope3/branches/3.3/src/zope/app/file/image.py	2007-06-14 14:02:00 UTC (rev 76699)
@@ -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: Zope3/branches/3.3/src/zope/app/file/tests/test_image.py
===================================================================
--- Zope3/branches/3.3/src/zope/app/file/tests/test_image.py	2007-06-14 13:57:46 UTC (rev 76698)
+++ Zope3/branches/3.3/src/zope/app/file/tests/test_image.py	2007-06-14 14:02:00 UTC (rev 76699)
@@ -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 Zope3-Checkins mailing list