Small todo note about ApiMain
[lhc/web/wiklou.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
17 /**
18 * @param $file
19 * @return bool
20 */
21 function mustRender( $file ) {
22 return true;
23 }
24
25 /**
26 * Render files as PNG
27 *
28 * @param $text
29 * @param $mime
30 * @param $params
31 * @return array
32 */
33 function getThumbType( $text, $mime, $params = null ) {
34 return array( 'png', 'image/png' );
35 }
36
37 /**
38 * Get width and height from the bmp header.
39 *
40 * @param $image
41 * @param $filename
42 * @return array
43 */
44 function getImageSize( $image, $filename ) {
45 $f = fopen( $filename, 'rb' );
46 if( !$f ) {
47 return false;
48 }
49 $header = fread( $f, 54 );
50 fclose($f);
51
52 // Extract binary form of width and height from the header
53 $w = substr( $header, 18, 4);
54 $h = substr( $header, 22, 4);
55
56 // Convert the unsigned long 32 bits (little endian):
57 try {
58 $w = wfUnpack( 'V', $w, 4 );
59 $h = wfUnpack( 'V', $h, 4 );
60 } catch ( MWException $e ) {
61 return false;
62 }
63 return array( $w[1], $h[1] );
64 }
65 }