Add support for microsoft bmp format. It simply give out the height and size,
authorAntoine Musso <hashar@users.mediawiki.org>
Sun, 22 Apr 2007 17:34:09 +0000 (17:34 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Sun, 22 Apr 2007 17:34:09 +0000 (17:34 +0000)
we might want to transform them to png automaticly.

includes/AutoLoader.php
includes/DefaultSettings.php
includes/media/BMP.php [new file with mode: 0644]
includes/media/Generic.php

index 596e6f8..a83216f 100644 (file)
@@ -251,6 +251,7 @@ function __autoload($className) {
 
                # Media
                'BitmapHandler' => 'includes/media/Bitmap.php',
+               'BmpHandler' => 'includes/media/BMP.php',
                'DjVuHandler' => 'includes/media/DjVu.php',
                'MediaHandler' => 'includes/media/Generic.php',
                'ImageHandler' => 'includes/media/Generic.php',
index b80b201..3b7bfc9 100644 (file)
@@ -1460,6 +1460,7 @@ $wgMediaHandlers = array(
        'image/jpeg' => 'BitmapHandler',
        'image/png' => 'BitmapHandler',
        'image/gif' => 'BitmapHandler',
+       'image/x-ms-bmp' => 'BmpHandler',
        'image/svg+xml' => 'SvgHandler',
        'image/vnd.djvu' => 'DjVuHandler',
 );
diff --git a/includes/media/BMP.php b/includes/media/BMP.php
new file mode 100644 (file)
index 0000000..e867819
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+/**
+ * Handler for Microsoft bitmap format (bmp). It inherits most of the methods
+ * from ImageHandler, some of them had to be overriden cause gd does not
+ * support this format.
+ */
+class BmpHandler extends BitmapHandler {
+
+       /*
+        * Get width and height from the bmp header.
+        */
+       function getImageSize( $image, $filename ) {
+               $f = fopen( $filename, 'r' );
+               if(!$f) return false;
+               $header = fread( $f, 54 );
+               fclose($f);
+
+               // Extract binary form of width and height from the header
+               $w = substr( $header, 18, 4);
+               $h = substr( $header, 22, 4);
+
+               // Convert the unsigned long 32 bits (little endian):
+               $w = unpack( 'V' , $w );
+               $h = unpack( 'V' , $h );
+               return array( $w[1], $h[1] );
+       }
+}
+
+?>
index 44c08d7..ba4e32e 100644 (file)
@@ -21,6 +21,7 @@ abstract class MediaHandler {
        static function getHandler( $type ) {
                global $wgMediaHandlers;
                if ( !isset( $wgMediaHandlers[$type] ) ) {
+                       wfDebug( __METHOD__ . ": no handler found for $type.\n");
                        return false;
                }
                $class = $wgMediaHandlers[$type];