MediaWiki  1.23.13
XCF.php
Go to the documentation of this file.
1 <?php
35 class XCFHandler extends BitmapHandler {
40  function mustRender( $file ) {
41  return true;
42  }
43 
52  function getThumbType( $ext, $mime, $params = null ) {
53  return array( 'png', 'image/png' );
54  }
55 
63  function getImageSize( $image, $filename ) {
64  return self::getXCFMetaData( $filename );
65  }
66 
77  static function getXCFMetaData( $filename ) {
78  # Decode master structure
79  $f = fopen( $filename, 'rb' );
80  if ( !$f ) {
81  return false;
82  }
83  # The image structure always starts at offset 0 in the XCF file.
84  # So we just read it :-)
85  $binaryHeader = fread( $f, 26 );
86  fclose( $f );
87 
88  # Master image structure:
89  #
90  # byte[9] "gimp xcf " File type magic
91  # byte[4] version XCF version
92  # "file" - version 0
93  # "v001" - version 1
94  # "v002" - version 2
95  # byte 0 Zero-terminator for version tag
96  # uint32 width With of canvas
97  # uint32 height Height of canvas
98  # uint32 base_type Color mode of the image; one of
99  # 0: RGB color
100  # 1: Grayscale
101  # 2: Indexed color
102  # (enum GimpImageBaseType in libgimpbase/gimpbaseenums.h)
103  try {
104  $header = wfUnpack(
105  "A9magic" . # A: space padded
106  "/a5version" . # a: zero padded
107  "/Nwidth" . # \
108  "/Nheight" . # N: unsigned long 32bit big endian
109  "/Nbase_type", # /
110  $binaryHeader
111  );
112  } catch ( MWException $mwe ) {
113  return false;
114  }
115 
116  # Check values
117  if ( $header['magic'] !== 'gimp xcf' ) {
118  wfDebug( __METHOD__ . " '$filename' has invalid magic signature.\n" );
119 
120  return false;
121  }
122  # TODO: we might want to check for sane values of width and height
123 
124  wfDebug( __METHOD__ .
125  ": canvas size of '$filename' is {$header['width']} x {$header['height']} px\n" );
126 
127  # Forge a return array containing metadata information just like getimagesize()
128  # See PHP documentation at: http://www.php.net/getimagesize
129  $metadata = array();
130  $metadata[0] = $header['width'];
131  $metadata[1] = $header['height'];
132  $metadata[2] = null; # IMAGETYPE constant, none exist for XCF.
133  $metadata[3] = sprintf(
134  'height="%s" width="%s"', $header['height'], $header['width']
135  );
136  $metadata['mime'] = 'image/x-xcf';
137  $metadata['channels'] = null;
138  $metadata['bits'] = 8; # Always 8-bits per color
139 
140  assert( '7 == count($metadata); ' .
141  '# return array must contains 7 elements just like getimagesize() return' );
142 
143  return $metadata;
144  }
145 
153  protected static function getScalerType( $dstPath, $checkDstPath = true ) {
154  return "im";
155  }
156 }
XCFHandler\getScalerType
static getScalerType( $dstPath, $checkDstPath=true)
Must use "im" for XCF.
Definition: XCF.php:153
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
$mime
usually copyright or history_copyright This message must be in HTML not wikitext $subpages will be ignored and the rest of subPageSubtitle() will run. 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink' whether MediaWiki currently thinks this is a CSS JS page Hooks may change this value to override the return value of Title::isCssOrJsPage(). 'TitleIsAlwaysKnown' whether MediaWiki currently thinks this page is known isMovable() always returns false. $title whether MediaWiki currently thinks this page is movable Hooks may change this value to override the return value of Title::isMovable(). 'TitleIsWikitextPage' whether MediaWiki currently thinks this is a wikitext page Hooks may change this value to override the return value of Title::isWikitextPage() 'TitleMove' use UploadVerification and UploadVerifyFile instead where the first element is the message key and the remaining elements are used as parameters to the message based on mime etc Preferred in most cases over UploadVerification object with all info about the upload string $mime
Definition: hooks.txt:2578
XCFHandler\getImageSize
getImageSize( $image, $filename)
Get width and height from the XCF header.
Definition: XCF.php:63
XCFHandler
Handler for the Gimp's native file format; getimagesize() doesn't support these files.
Definition: XCF.php:35
$f
$f
Definition: UtfNormalTest2.php:38
wfUnpack
wfUnpack( $format, $data, $length=false)
Wrapper around php's unpack.
Definition: GlobalFunctions.php:4076
$params
$params
Definition: styleTest.css.php:40
MWException
MediaWiki exception.
Definition: MWException.php:26
BitmapHandler
Generic handler for bitmap images.
Definition: Bitmap.php:29
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
XCFHandler\getThumbType
getThumbType( $ext, $mime, $params=null)
Render files as PNG.
Definition: XCF.php:52
wfDebug
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:980
XCFHandler\getXCFMetaData
static getXCFMetaData( $filename)
Metadata for a given XCF file.
Definition: XCF.php:77
$file
if(PHP_SAPI !='cli') $file
Definition: UtfNormalTest2.php:30
XCFHandler\mustRender
mustRender( $file)
Definition: XCF.php:40
$ext
$ext
Definition: NoLocalSettings.php:34
color
in the sidebar</td >< td > font color
Definition: All_system_messages.txt:425