MediaWiki
REL1_23
|
00001 <?php 00035 class XCFHandler extends BitmapHandler { 00040 function mustRender( $file ) { 00041 return true; 00042 } 00043 00052 function getThumbType( $ext, $mime, $params = null ) { 00053 return array( 'png', 'image/png' ); 00054 } 00055 00063 function getImageSize( $image, $filename ) { 00064 return self::getXCFMetaData( $filename ); 00065 } 00066 00077 static function getXCFMetaData( $filename ) { 00078 # Decode master structure 00079 $f = fopen( $filename, 'rb' ); 00080 if ( !$f ) { 00081 return false; 00082 } 00083 # The image structure always starts at offset 0 in the XCF file. 00084 # So we just read it :-) 00085 $binaryHeader = fread( $f, 26 ); 00086 fclose( $f ); 00087 00088 # Master image structure: 00089 # 00090 # byte[9] "gimp xcf " File type magic 00091 # byte[4] version XCF version 00092 # "file" - version 0 00093 # "v001" - version 1 00094 # "v002" - version 2 00095 # byte 0 Zero-terminator for version tag 00096 # uint32 width With of canvas 00097 # uint32 height Height of canvas 00098 # uint32 base_type Color mode of the image; one of 00099 # 0: RGB color 00100 # 1: Grayscale 00101 # 2: Indexed color 00102 # (enum GimpImageBaseType in libgimpbase/gimpbaseenums.h) 00103 try { 00104 $header = wfUnpack( 00105 "A9magic" . # A: space padded 00106 "/a5version" . # a: zero padded 00107 "/Nwidth" . # \ 00108 "/Nheight" . # N: unsigned long 32bit big endian 00109 "/Nbase_type", # / 00110 $binaryHeader 00111 ); 00112 } catch ( MWException $mwe ) { 00113 return false; 00114 } 00115 00116 # Check values 00117 if ( $header['magic'] !== 'gimp xcf' ) { 00118 wfDebug( __METHOD__ . " '$filename' has invalid magic signature.\n" ); 00119 00120 return false; 00121 } 00122 # TODO: we might want to check for sane values of width and height 00123 00124 wfDebug( __METHOD__ . 00125 ": canvas size of '$filename' is {$header['width']} x {$header['height']} px\n" ); 00126 00127 # Forge a return array containing metadata information just like getimagesize() 00128 # See PHP documentation at: http://www.php.net/getimagesize 00129 $metadata = array(); 00130 $metadata[0] = $header['width']; 00131 $metadata[1] = $header['height']; 00132 $metadata[2] = null; # IMAGETYPE constant, none exist for XCF. 00133 $metadata[3] = sprintf( 00134 'height="%s" width="%s"', $header['height'], $header['width'] 00135 ); 00136 $metadata['mime'] = 'image/x-xcf'; 00137 $metadata['channels'] = null; 00138 $metadata['bits'] = 8; # Always 8-bits per color 00139 00140 assert( '7 == count($metadata); ' . 00141 '# return array must contains 7 elements just like getimagesize() return' ); 00142 00143 return $metadata; 00144 } 00145 00153 protected static function getScalerType( $dstPath, $checkDstPath = true ) { 00154 return "im"; 00155 } 00156 }