MediaWiki master
BmpHandler.php
Go to the documentation of this file.
1<?php
10namespace MediaWiki\Media;
11
15
27 public function mustRender( $file ) {
28 return true;
29 }
30
39 public function getThumbType( $ext, $mime, $params = null ) {
40 return [ 'png', 'image/png' ];
41 }
42
50 public function getSizeAndMetadata( $state, $filename ) {
51 $f = fopen( $filename, 'rb' );
52 if ( !$f ) {
53 return [];
54 }
55 $header = fread( $f, 54 );
56 fclose( $f );
57
58 // Extract binary form of width and height from the header
59 $w = substr( $header, 18, 4 );
60 $h = substr( $header, 22, 4 );
61
62 // Convert the unsigned long 32 bits (little endian):
63 try {
64 $w = StringUtils::unpack( 'V', $w, 4 );
65 $h = StringUtils::unpack( 'V', $h, 4 );
66 } catch ( UnpackFailedException ) {
67 return [];
68 }
69
70 return [
71 'width' => $w[1],
72 'height' => $h[1]
73 ];
74 }
75}
76
78class_alias( BmpHandler::class, 'BmpHandler' );
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition File.php:79
Generic handler for bitmap images.
Handler for Microsoft's bitmap format; getimagesize() doesn't support these files.
getThumbType( $ext, $mime, $params=null)
Render files as PNG.
getSizeAndMetadata( $state, $filename)
Get width and height from the bmp header.
A collection of static methods to play with strings.