return $wgLang->commaList( $info );
}
+
+ /**
+ * Return the duration of the GIF file.
+ *
+ * Shown in the &query=imageinfo&iiprop=size api query.
+ *
+ * @param $file File
+ * @return float The duration of the file.
+ */
+ public function getLength( $file ) {
+ $serMeta = $file->getMetadata();
+ MediaWiki\suppressWarnings();
+ $metadata = unserialize( $serMeta );
+ MediaWiki\restoreWarnings();
+
+ if ( !$metadata || !isset( $metadata['duration'] ) || !$metadata['duration'] ) {
+ return 0.0;
+ } else {
+ return (float)$metadata['duration'];
+ }
+ }
}
return $wgLang->commaList( $info );
}
+ /**
+ * Return the duration of an APNG file.
+ *
+ * Shown in the &query=imageinfo&iiprop=size api query.
+ *
+ * @param $file File
+ * @return float The duration of the file.
+ */
+ public function getLength( $file ) {
+ $serMeta = $file->getMetadata();
+ MediaWiki\suppressWarnings();
+ $metadata = unserialize( $serMeta );
+ MediaWiki\restoreWarnings();
+
+ if ( !$metadata || !isset( $metadata['duration'] ) || !$metadata['duration'] ) {
+ return 0.0;
+ } else {
+ return (float)$metadata['duration'];
+ }
+ }
+
// PNGs should be easy to support, but it will need some sharpening applied
// and another user test to check if the perceived quality change is noticeable
-
public function supportsBucketing() {
return false;
}
),
);
}
+
+ /**
+ * @param $filename string
+ * @param $expectedLength float
+ * @dataProvider provideGetLength
+ */
+ public function testGetLength( $filename, $expectedLength ) {
+ $file = $this->dataFile( $filename, 'image/gif' );
+ $actualLength = $file->getLength();
+ $this->assertEquals( $expectedLength, $actualLength, '', 0.00001 );
+ }
+
+ public function provideGetLength() {
+ return array(
+ array( 'animated.gif', 2.4 ),
+ array( 'animated-xmp.gif', 2.4 ),
+ array( 'nonanimated', 0.0 ),
+ array( 'Bishzilla_blink.gif', 1.4 ),
+ );
+ }
}
),
);
}
+
+ /**
+ * @param $filename string
+ * @param $expectedLength float
+ * @dataProvider provideGetLength
+ */
+ public function testGetLength( $filename, $expectedLength ) {
+ $file = $this->dataFile( $filename, 'image/png' );
+ $actualLength = $file->getLength();
+ $this->assertEquals( $expectedLength, $actualLength, '', 0.00001 );
+ }
+
+ public function provideGetLength() {
+ return array(
+ array( 'Animated_PNG_example_bouncing_beach_ball.png', 1.5 ),
+ array( 'Png-native-test.png', 0.0 ),
+ array( 'greyscale-png.png', 0.0 ),
+ array( '1bit-png.png', 0.0 ),
+ );
+ }
}