Add a isAnimatedImage() helper function to imagehandlers.
[lhc/web/wiklou.git] / includes / media / GIF.php
1 <?php
2 /**
3 * @file
4 * @ingroup Media
5 */
6
7 /**
8 * Handler for GIF images.
9 *
10 * @ingroup Media
11 */
12 class GIFHandler extends BitmapHandler {
13
14 function getMetadata( $image, $filename ) {
15 if ( !isset($image->parsedGIFMetadata) ) {
16 try {
17 $image->parsedGIFMetadata = GIFMetadataExtractor::getMetadata( $filename );
18 } catch( Exception $e ) {
19 // Broken file?
20 wfDebug( __METHOD__ . ': ' . $e->getMessage() . "\n" );
21 return '0';
22 }
23 }
24
25 return serialize($image->parsedGIFMetadata);
26
27 }
28
29 function formatMetadata( $image ) {
30 return false;
31 }
32
33 function getImageArea( $image, $width, $height ) {
34 $ser = $image->getMetadata();
35 if ($ser) {
36 $metadata = unserialize($ser);
37 return $width * $height * $metadata['frameCount'];
38 } else {
39 return $width * $height;
40 }
41 }
42
43 function isAnimatedImage( $image ) {
44 $ser = $image->getMetadata();
45 if ($ser) {
46 $metadata = unserialize($ser);
47 if( $metadata['frameCount'] > 1 ) return true;
48 }
49 return false;
50 }
51
52 function getMetadataType( $image ) {
53 return 'parsed-gif';
54 }
55
56 function isMetadataValid( $image, $metadata ) {
57 $data = @unserialize( $metadata );
58 return (boolean) $data;
59 }
60
61 function getLongDesc( $image ) {
62 global $wgUser, $wgLang;
63 $sk = $wgUser->getSkin();
64
65 $metadata = @unserialize($image->getMetadata());
66
67 if (!$metadata) return parent::getLongDesc( $image );
68
69 $info = array();
70 $info[] = $image->getMimeType();
71 $info[] = $sk->formatSize( $image->getSize() );
72
73 if ($metadata['looped'])
74 $info[] = wfMsgExt( 'file-info-gif-looped', 'parseinline' );
75
76 if ($metadata['frameCount'] > 1)
77 $info[] = wfMsgExt( 'file-info-gif-frames', 'parseinline', $metadata['frameCount'] );
78
79 if ($metadata['duration'])
80 $info[] = $wgLang->formatTimePeriod( $metadata['duration'] );
81
82 $infoString = $wgLang->commaList( $info );
83
84 return "($infoString)";
85 }
86 }