45 return [
'png',
'image/png' ];
58 private static function getXCFMetaData( $filename ) {
59 # Decode master structure
60 $f = fopen( $filename,
'rb' );
64 # The image structure always starts at offset 0 in the XCF file.
65 # So we just read it :-)
66 $binaryHeader = fread( $f, 26 );
87 $header = StringUtils::unpack(
88 "A9magic" . # A: space padded
89 "/a5version" . # a: zero padded
91 "/Nheight" . # N: unsigned long 32bit big endian
95 }
catch ( UnpackFailedException ) {
100 if ( $header[
'magic'] !==
'gimp xcf' ) {
101 wfDebug( __METHOD__ .
" '$filename' has invalid magic signature." );
105 # TODO: we might want to check for correct values of width and height
108 ": canvas size of '$filename' is {$header['width']} x {$header['height']} px" );
115 $header = self::getXCFMetaData( $filename );
121 switch ( $header[
'base_type'] ) {
123 $metadata[
'colorType'] =
'truecolour-alpha';
126 $metadata[
'colorType'] =
'greyscale-alpha';
129 $metadata[
'colorType'] =
'index-coloured';
132 $metadata[
'colorType'] =
'unknown';
136 $metadata[
'error'] =
true;
139 'width' => $header[
'width'] ?? 0,
140 'height' => $header[
'height'] ?? 0,
142 'metadata' => $metadata
153 if ( !$file->getMetadataArray() ) {
175 $xcfMeta = $file->getMetadataArray();
176 if ( isset( $xcfMeta[
'colorType'] ) && $xcfMeta[
'colorType'] ===
'index-coloured' ) {
179 return parent::canRender( $file );
184class_alias( XCFHandler::class,
'XCFHandler' );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.