Go to the documentation of this file.
34 const MINIMUM_CHUNK_HEADER_LENGTH = 18;
38 const _MW_WEBP_VERSION = 1;
48 if ( !$parsedWebPData ) {
52 $parsedWebPData[
'metadata'][
'_MW_WEBP_VERSION'] = self::_MW_WEBP_VERSION;
61 if ( $metadata === self::BROKEN_FILE ) {
66 Wikimedia\suppressWarnings();
68 Wikimedia\restoreWarnings();
70 if ( !$data || !is_array( $data ) ) {
71 wfDebug( __METHOD__ .
" invalid WebP metadata\n" );
76 if ( !isset( $data[
'metadata'][
'_MW_WEBP_VERSION'] )
77 || $data[
'metadata'][
'_MW_WEBP_VERSION'] != self::_MW_WEBP_VERSION
79 wfDebug( __METHOD__ .
" old but compatible WebP metadata\n" );
95 wfDebugLog(
'WebP', __METHOD__ .
": Extracting metadata from $filename\n" );
98 if ( $info ===
false ) {
99 wfDebugLog(
'WebP', __METHOD__ .
": Not a valid RIFF file\n" );
103 if ( $info[
'fourCC'] !=
'WEBP' ) {
104 wfDebugLog(
'WebP', __METHOD__ .
': FourCC was not WEBP: ' .
105 bin2hex( $info[
'fourCC'] ) .
" \n" );
111 wfDebugLog(
'WebP', __METHOD__ .
": No VP8 chunks found\n" );
128 foreach ( $chunks
as $chunk ) {
129 if ( !in_array( $chunk[
'fourCC'], [
'VP8 ',
'VP8L',
'VP8X' ] ) ) {
134 $chunkHeader = file_get_contents( $filename,
false,
null,
135 $chunk[
'start'], self::MINIMUM_CHUNK_HEADER_LENGTH );
136 wfDebugLog(
'WebP', __METHOD__ .
": {$chunk['fourCC']}\n" );
138 switch ( $chunk[
'fourCC'] ) {
140 return array_merge( $vp8Info,
141 self::decodeLossyChunkHeader( $chunkHeader ) );
143 return array_merge( $vp8Info,
144 self::decodeLosslessChunkHeader( $chunkHeader ) );
146 $vp8Info = array_merge( $vp8Info,
147 self::decodeExtendedChunkHeader( $chunkHeader ) );
165 $syncCode = substr(
$header, 11, 3 );
166 if ( $syncCode !=
"\x9D\x01\x2A" ) {
167 wfDebugLog(
'WebP', __METHOD__ .
': Invalid sync code: ' .
168 bin2hex( $syncCode ) .
"\n" );
172 $imageSize = unpack(
'v2', substr(
$header, 14, 4 ) );
175 'compression' =>
'lossy',
176 'width' => $imageSize[1] & 0x3FFF,
177 'height' => $imageSize[2] & 0x3FFF
191 wfDebugLog(
'WebP', __METHOD__ .
': Invalid signature: ' .
192 bin2hex(
$header{8} ) .
"\n" );
197 $imageSize = unpack(
'C4', substr(
$header, 9, 4 ) );
199 'compression' =>
'lossless',
200 'width' => ( $imageSize[1] | ( ( $imageSize[2] & 0x3F ) << 8 ) ) + 1,
201 'height' => ( ( ( $imageSize[2] & 0xC0 ) >> 6 ) |
202 ( $imageSize[3] << 2 ) | ( ( $imageSize[4] & 0x03 ) << 10 ) ) + 1
215 $flags = unpack(
'c', substr(
$header, 8, 1 ) );
218 $width = unpack(
'V', substr(
$header, 12, 3 ) .
"\x00" );
219 $height = unpack(
'V', substr(
$header, 15, 3 ) .
"\x00" );
222 'compression' =>
'unknown',
225 'width' => ( $width[1] & 0xFFFFFF ) + 1,
226 'height' => ( $height[1] & 0xFFFFFF ) + 1
231 if ( $file ===
null ) {
234 if ( $metadata ===
false && $file instanceof
File ) {
235 $metadata = $file->getMetadata();
238 Wikimedia\suppressWarnings();
240 Wikimedia\restoreWarnings();
242 if ( $metadata ==
false ) {
245 return [ $metadata[
'width'], $metadata[
'height'] ];
261 if ( self::isAnimatedImage( $file ) ) {
272 $ser =
$image->getMetadata();
275 if ( isset( $metadata[
'animated'] ) && $metadata[
'animated'] ===
true ) {
296 return [
'png',
'image/png' ];
getMetadataType( $image)
Get a string describing the type of metadata, for display purposes.
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
static decodeExtendedChunkHeader( $header)
Decodes an extended chunk header.
Implements some public methods and some protected utility functions which are required by multiple ch...
Generic handler for bitmap images.
getImageSize( $file, $path, $metadata=false)
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check $image
if( $ext=='php'|| $ext=='php5') $mime
getScalerType( $dstPath, $checkDstPath=true)
Must use "im" for XCF.
static decodeLossyChunkHeader( $header)
Decodes a lossy chunk header.
unserialize( $serialized)
getThumbType( $ext, $mime, $params=null)
Render files as PNG.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
canAnimateThumbnail( $file)
If the material is animated, we can animate the thumbnail.
getMetadata( $image, $filename)
Get handler-specific metadata which will be saved in the img_metadata field.
static decodeLosslessChunkHeader( $header)
Decodes a lossless chunk header.
Handler for Google's WebP format https://developers.google.com/speed/webp/
static extractMetadataFromChunks( $chunks, $filename)
Extracts the image size and WebP type from a file based on the chunk list.
isMetadataValid( $image, $metadata)
Check if the metadata string is valid for this handler.
static extractMetadata( $filename)
Extracts the image size and WebP type from a file.