wiki.techinc.nl/includes/media/GIF.php

87 lines
1.8 KiB
PHP
Raw Normal View History

<?php
/**
* @file
* @ingroup Media
*/
/**
* Handler for GIF images.
*
* @ingroup Media
*/
class GIFHandler extends BitmapHandler {
function getMetadata( $image, $filename ) {
if ( !isset($image->parsedGIFMetadata) ) {
try {
$image->parsedGIFMetadata = GIFMetadataExtractor::getMetadata( $filename );
} catch( Exception $e ) {
// Broken file?
wfDebug( __METHOD__ . ': ' . $e->getMessage() . "\n" );
return '0';
}
}
2009-08-04 08:54:31 +00:00
return serialize($image->parsedGIFMetadata);
}
function formatMetadata( $image ) {
return false;
}
function getImageArea( $image, $width, $height ) {
2009-08-10 11:12:04 +00:00
$ser = $image->getMetadata();
2009-08-10 11:04:30 +00:00
if ($ser) {
$metadata = unserialize($ser);
2009-08-10 09:32:55 +00:00
return $width * $height * $metadata['frameCount'];
} else {
return $width * $height;
}
}
function isAnimatedImage( $image ) {
$ser = $image->getMetadata();
if ($ser) {
$metadata = unserialize($ser);
if( $metadata['frameCount'] > 1 ) return true;
}
return false;
}
function getMetadataType( $image ) {
return 'parsed-gif';
}
function isMetadataValid( $image, $metadata ) {
$data = @unserialize( $metadata );
return (boolean) $data;
}
function getLongDesc( $image ) {
global $wgUser, $wgLang;
$sk = $wgUser->getSkin();
2009-08-06 22:55:44 +00:00
$metadata = @unserialize($image->getMetadata());
if (!$metadata) return parent::getLongDesc( $image );
$info = array();
$info[] = $image->getMimeType();
$info[] = $sk->formatSize( $image->getSize() );
if ($metadata['looped'])
$info[] = wfMsgExt( 'file-info-gif-looped', 'parseinline' );
if ($metadata['frameCount'] > 1)
$info[] = wfMsgExt( 'file-info-gif-frames', 'parseinline', $metadata['frameCount'] );
if ($metadata['duration'])
$info[] = $wgLang->formatTimePeriod( $metadata['duration'] );
$infoString = $wgLang->commaList( $info );
return "($infoString)";
}
}