* Standardised file description headers
[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 function isAnimatedImage( $image ) {
36 $ser = $image->getMetadata();
37 if ($ser) {
38 $metadata = unserialize($ser);
39 if( $metadata['frameCount'] > 1 ) return true;
40 }
41 return false;
42 }
43
44 function getMetadataType( $image ) {
45 return 'parsed-png';
46 }
47
48 function isMetadataValid( $image, $metadata ) {
49 wfSuppressWarnings();
50 $data = unserialize( $metadata );
51 wfRestoreWarnings();
52 return (boolean) $data;
53 }
54 function getLongDesc( $image ) {
55 global $wgLang;
56 $original = parent::getLongDesc( $image );
57
58 wfSuppressWarnings();
59 $metadata = unserialize($image->getMetadata());
60 wfRestoreWarnings();
61
62 if( !$metadata || $metadata['frameCount'] <= 0 )
63 return $original;
64
65 $info = array();
66 $info[] = substr( $original, 1, strlen( $original )-2 );
67
68 if ($metadata['loopCount'] == 0)
69 $info[] = wfMsgExt( 'file-info-png-looped', 'parseinline' );
70 elseif ($metadata['loopCount'] > 1)
71 $info[] = wfMsgExt( 'file-info-png-repeat', 'parseinline', $metadata['loopCount'] );;
72
73 if ($metadata['frameCount'] > 0)
74 $info[] = wfMsgExt( 'file-info-png-frames', 'parseinline', $metadata['frameCount'] );
75
76 if ($metadata['duration'])
77 $info[] = $wgLang->formatTimePeriod( $metadata['duration'] );
78
79 $infoString = $wgLang->commaList( $info );
80
81 return "($infoString)";
82 }
83
84 }