Parameter documentation
[lhc/web/wiklou.git] / includes / media / GIF.php
1 <?php
2 /**
3 * Handler for GIF images.
4 *
5 * @file
6 * @ingroup Media
7 */
8
9 /**
10 * Handler for GIF images.
11 *
12 * @ingroup Media
13 */
14 class GIFHandler extends BitmapHandler {
15
16 function getMetadata( $image, $filename ) {
17 if ( !isset( $image->parsedGIFMetadata ) ) {
18 try {
19 $image->parsedGIFMetadata = GIFMetadataExtractor::getMetadata( $filename );
20 } catch( Exception $e ) {
21 // Broken file?
22 wfDebug( __METHOD__ . ': ' . $e->getMessage() . "\n" );
23 return '0';
24 }
25 }
26
27 return serialize( $image->parsedGIFMetadata );
28
29 }
30
31 function formatMetadata( $image ) {
32 return false;
33 }
34
35 /**
36 * @param $image File
37 * @param $width
38 * @param $height
39 * @return
40 */
41 function getImageArea( $image, $width, $height ) {
42 $ser = $image->getMetadata();
43 if ($ser) {
44 $metadata = unserialize($ser);
45 return $width * $height * $metadata['frameCount'];
46 } else {
47 return $width * $height;
48 }
49 }
50
51 /**
52 * @param $image File
53 * @return bool
54 */
55 function isAnimatedImage( $image ) {
56 $ser = $image->getMetadata();
57 if ($ser) {
58 $metadata = unserialize($ser);
59 if( $metadata['frameCount'] > 1 ) return true;
60 }
61 return false;
62 }
63
64 function getMetadataType( $image ) {
65 return 'parsed-gif';
66 }
67
68 function isMetadataValid( $image, $metadata ) {
69 wfSuppressWarnings();
70 $data = unserialize( $metadata );
71 wfRestoreWarnings();
72 return (boolean) $data;
73 }
74
75 /**
76 * @param $image File
77 * @return string
78 */
79 function getLongDesc( $image ) {
80 global $wgLang;
81
82 $original = parent::getLongDesc( $image );
83
84 wfSuppressWarnings();
85 $metadata = unserialize($image->getMetadata());
86 wfRestoreWarnings();
87
88 if (!$metadata || $metadata['frameCount'] <= 1)
89 return $original;
90
91 /* Preserve original image info string, but strip the last char ')' so we can add even more */
92 $info = array();
93 $info[] = $original;
94
95 if ($metadata['looped'])
96 $info[] = wfMsgExt( 'file-info-gif-looped', 'parseinline' );
97
98 if ($metadata['frameCount'] > 1)
99 $info[] = wfMsgExt( 'file-info-gif-frames', 'parseinline', $metadata['frameCount'] );
100
101 if ($metadata['duration'])
102 $info[] = $wgLang->formatTimePeriod( $metadata['duration'] );
103
104 return $wgLang->commaList( $info );
105 }
106 }