3 * Handler for PNG images.
10 * Handler for PNG images.
14 class PNGHandler
extends BitmapHandler
{
16 const BROKEN_FILE
= '0';
20 * @param string $filename
23 function getMetadata( $image, $filename ) {
25 $metadata = BitmapMetadataHandler
::PNG( $filename );
26 } catch( Exception
$e ) {
28 wfDebug( __METHOD__
. ': ' . $e->getMessage() . "\n" );
29 return self
::BROKEN_FILE
;
32 return serialize($metadata);
39 function formatMetadata( $image ) {
40 $meta = $image->getMetadata();
45 $meta = unserialize( $meta );
46 if ( !isset( $meta['metadata'] ) ||
count( $meta['metadata'] ) <= 1 ) {
50 if ( isset( $meta['metadata']['_MW_PNG_VERSION'] ) ) {
51 unset( $meta['metadata']['_MW_PNG_VERSION'] );
53 return $this->formatMetadataHelper( $meta['metadata'] );
60 function isAnimatedImage( $image ) {
61 $ser = $image->getMetadata();
63 $metadata = unserialize($ser);
64 if( $metadata['frameCount'] > 1 ) return true;
69 function getMetadataType( $image ) {
73 function isMetadataValid( $image, $metadata ) {
75 if ( $metadata === self
::BROKEN_FILE
) {
76 // Do not repetitivly regenerate metadata on broken file.
77 return self
::METADATA_GOOD
;
81 $data = unserialize( $metadata );
84 if ( !$data ||
!is_array( $data ) ) {
85 wfDebug(__METHOD__
. ' invalid png metadata' );
86 return self
::METADATA_BAD
;
89 if ( !isset( $data['metadata']['_MW_PNG_VERSION'] )
90 ||
$data['metadata']['_MW_PNG_VERSION'] != PNGMetadataExtractor
::VERSION
) {
91 wfDebug(__METHOD__
. ' old but compatible png metadata' );
92 return self
::METADATA_COMPATIBLE
;
94 return self
::METADATA_GOOD
;
101 function getLongDesc( $image ) {
103 $original = parent
::getLongDesc( $image );
105 wfSuppressWarnings();
106 $metadata = unserialize($image->getMetadata());
109 if( !$metadata ||
$metadata['frameCount'] <= 0 )
115 if ( $metadata['loopCount'] == 0 ) {
116 $info[] = wfMsgExt( 'file-info-png-looped', 'parseinline' );
117 } elseif ( $metadata['loopCount'] > 1 ) {
118 $info[] = wfMsgExt( 'file-info-png-repeat', 'parseinline', $metadata['loopCount'] );
121 if ( $metadata['frameCount'] > 0 ) {
122 $info[] = wfMsgExt( 'file-info-png-frames', 'parseinline', $metadata['frameCount'] );
125 if ( $metadata['duration'] ) {
126 $info[] = $wgLang->formatTimePeriod( $metadata['duration'] );
129 return $wgLang->commaList( $info );