Fix Bug #30322 “SVG metadata is read incorrectly” by applying supplied patch
[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, 'r' );
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 $w = unpack( 'V' , $w );
58 $h = unpack( 'V' , $h );
59 return array( $w[1], $h[1] );
60 }
61 }