51 if ( !$parsedWebPData ) {
64 if ( $metadata === self::BROKEN_FILE ) {
69 Wikimedia\suppressWarnings();
71 Wikimedia\restoreWarnings();
73 if ( !$data || !is_array( $data ) ) {
74 wfDebug( __METHOD__ .
" invalid WebP metadata" );
79 if ( !isset( $data[
'metadata'][
'_MW_WEBP_VERSION'] )
80 || $data[
'metadata'][
'_MW_WEBP_VERSION'] != self::_MW_WEBP_VERSION
82 wfDebug( __METHOD__ .
" old but compatible WebP metadata" );
98 wfDebugLog(
'WebP', __METHOD__ .
": Extracting metadata from $filename" );
101 if ( $info ===
false ) {
102 wfDebugLog(
'WebP', __METHOD__ .
": Not a valid RIFF file" );
106 if ( $info[
'fourCC'] !=
'WEBP' ) {
107 wfDebugLog(
'WebP', __METHOD__ .
': FourCC was not WEBP: ' .
108 bin2hex( $info[
'fourCC'] ) );
114 wfDebugLog(
'WebP', __METHOD__ .
": No VP8 chunks found" );
131 foreach ( $chunks as $chunk ) {
132 if ( !in_array( $chunk[
'fourCC'], [
'VP8 ',
'VP8L',
'VP8X' ] ) ) {
137 $chunkHeader = file_get_contents( $filename,
false,
null,
138 $chunk[
'start'], self::MINIMUM_CHUNK_HEADER_LENGTH );
139 wfDebugLog(
'WebP', __METHOD__ .
": {$chunk['fourCC']}" );
141 switch ( $chunk[
'fourCC'] ) {
143 return array_merge( $vp8Info,
144 self::decodeLossyChunkHeader( $chunkHeader ) );
146 return array_merge( $vp8Info,
147 self::decodeLosslessChunkHeader( $chunkHeader ) );
149 $vp8Info = array_merge( $vp8Info,
150 self::decodeExtendedChunkHeader( $chunkHeader ) );
168 $syncCode = substr(
$header, 11, 3 );
169 if ( $syncCode !=
"\x9D\x01\x2A" ) {
170 wfDebugLog(
'WebP', __METHOD__ .
': Invalid sync code: ' .
171 bin2hex( $syncCode ) );
175 $imageSize = unpack(
'v2', substr(
$header, 14, 4 ) );
178 'compression' =>
'lossy',
179 'width' => $imageSize[1] & 0x3FFF,
180 'height' => $imageSize[2] & 0x3FFF
194 wfDebugLog(
'WebP', __METHOD__ .
': Invalid signature: ' .
200 $imageSize = unpack(
'C4', substr(
$header, 9, 4 ) );
202 'compression' =>
'lossless',
203 'width' => ( $imageSize[1] | ( ( $imageSize[2] & 0x3F ) << 8 ) ) + 1,
204 'height' => ( ( ( $imageSize[2] & 0xC0 ) >> 6 ) |
205 ( $imageSize[3] << 2 ) | ( ( $imageSize[4] & 0x03 ) << 10 ) ) + 1
218 $flags = unpack(
'c', substr(
$header, 8, 1 ) );
221 $width = unpack(
'V', substr(
$header, 12, 3 ) .
"\x00" );
222 $height = unpack(
'V', substr(
$header, 15, 3 ) .
"\x00" );
225 'compression' =>
'unknown',
228 'width' => ( $width[1] & 0xFFFFFF ) + 1,
229 'height' => ( $height[1] & 0xFFFFFF ) + 1
234 if (
$file ===
null ) {
237 if ( $metadata ===
false &&
$file instanceof
File ) {
238 $metadata =
$file->getMetadata();
241 Wikimedia\suppressWarnings();
243 Wikimedia\restoreWarnings();
245 if ( $metadata ==
false ) {
248 return [ $metadata[
'width'], $metadata[
'height'] ];
264 if ( self::isAnimatedImage(
$file ) ) {
275 $ser = $image->getMetadata();
278 if ( isset( $metadata[
'animated'] ) && $metadata[
'animated'] ===
true ) {
299 return [
'png',
'image/png' ];
unserialize( $serialized)
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
Generic handler for bitmap images.
Implements some public methods and some protected utility functions which are required by multiple ch...
Handler for Google's WebP format https://developers.google.com/speed/webp/
isMetadataValid( $image, $metadata)
Check if the metadata string is valid for this handler.
canAnimateThumbnail( $file)
If the material is animated, we can animate the thumbnail.
const _MW_WEBP_VERSION
Version of the metadata stored in db records.
static extractMetadataFromChunks( $chunks, $filename)
Extracts the image size and WebP type from a file based on the chunk list.
getMetadata( $image, $filename)
Get handler-specific metadata which will be saved in the img_metadata field.
getScalerType( $dstPath, $checkDstPath=true)
Must use "im" for XCF.
static decodeLossyChunkHeader( $header)
Decodes a lossy chunk header.
getImageSize( $file, $path, $metadata=false)
const BROKEN_FILE
Value to store in img_metadata if there was an error extracting metadata.
const MINIMUM_CHUNK_HEADER_LENGTH
Minimum chunk header size to be able to read all header types.
getThumbType( $ext, $mime, $params=null)
Render files as PNG.
static decodeLosslessChunkHeader( $header)
Decodes a lossless chunk header.
getMetadataType( $image)
Get a string describing the type of metadata, for display purposes.
static extractMetadata( $filename)
Extracts the image size and WebP type from a file.
static decodeExtendedChunkHeader( $header)
Decodes an extended chunk header.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
if(!is_readable( $file)) $ext