Parameter documentation
[lhc/web/wiklou.git] / includes / media / PNG.php
1 <?php
2 /**
3 * Handler for PNG images.
4 *
5 * @file
6 * @ingroup Media
7 */
8
9 /**
10 * Handler for PNG images.
11 *
12 * @ingroup Media
13 */
14 class PNGHandler extends BitmapHandler {
15
16 function getMetadata( $image, $filename ) {
17 if ( !isset($image->parsedPNGMetadata) ) {
18 try {
19 $image->parsedPNGMetadata = PNGMetadataExtractor::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->parsedPNGMetadata);
28
29 }
30
31 function formatMetadata( $image ) {
32 return false;
33 }
34
35 /**
36 * @param $image File
37 * @return bool
38 */
39 function isAnimatedImage( $image ) {
40 $ser = $image->getMetadata();
41 if ($ser) {
42 $metadata = unserialize($ser);
43 if( $metadata['frameCount'] > 1 ) return true;
44 }
45 return false;
46 }
47
48 function getMetadataType( $image ) {
49 return 'parsed-png';
50 }
51
52 function isMetadataValid( $image, $metadata ) {
53 wfSuppressWarnings();
54 $data = unserialize( $metadata );
55 wfRestoreWarnings();
56 return (boolean) $data;
57 }
58
59 /**
60 * @param $image File
61 * @return string
62 */
63 function getLongDesc( $image ) {
64 global $wgLang;
65 $original = parent::getLongDesc( $image );
66
67 wfSuppressWarnings();
68 $metadata = unserialize($image->getMetadata());
69 wfRestoreWarnings();
70
71 if( !$metadata || $metadata['frameCount'] <= 0 )
72 return $original;
73
74 $info = array();
75 $info[] = $original;
76
77 if ($metadata['loopCount'] == 0)
78 $info[] = wfMsgExt( 'file-info-png-looped', 'parseinline' );
79 elseif ($metadata['loopCount'] > 1)
80 $info[] = wfMsgExt( 'file-info-png-repeat', 'parseinline', $metadata['loopCount'] );
81
82 if ($metadata['frameCount'] > 0)
83 $info[] = wfMsgExt( 'file-info-png-frames', 'parseinline', $metadata['frameCount'] );
84
85 if ($metadata['duration'])
86 $info[] = $wgLang->formatTimePeriod( $metadata['duration'] );
87
88 return $wgLang->commaList( $info );
89 }
90
91 }