]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/media/BMP.php
MediaWiki 1.17.0
[autoinstalls/mediawiki.git] / includes / media / BMP.php
1 <?php
2 /**
3  * Handler for Microsoft's bitmap format
4  *
5  * @file
6  * @ingroup Media
7  */
8
9 /**
10  * Handler for Microsoft's bitmap format; getimagesize() doesn't
11  * support these files
12  *
13  * @ingroup Media
14  */
15 class BmpHandler extends BitmapHandler {
16         // We never want to use .bmp in an <img/> tag
17         function mustRender( $file ) {
18                 return true;
19         }
20
21         // Render files as PNG
22         function getThumbType( $text, $mime, $params = null ) {
23                 return array( 'png', 'image/png' );
24         }
25
26         /*
27          * Get width and height from the bmp header.
28          */
29         function getImageSize( $image, $filename ) {
30                 $f = fopen( $filename, 'r' );
31                 if(!$f) return false;
32                 $header = fread( $f, 54 );
33                 fclose($f);
34
35                 // Extract binary form of width and height from the header
36                 $w = substr( $header, 18, 4);
37                 $h = substr( $header, 22, 4);
38
39                 // Convert the unsigned long 32 bits (little endian):
40                 $w = unpack( 'V' , $w );
41                 $h = unpack( 'V' , $h );
42                 return array( $w[1], $h[1] );
43         }
44 }