BMP.php 879 B

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