3 use MediaWiki\Shell\Shell
;
6 * Tests related to JPEG chroma subsampling via $wgJpegPixelFormat setting.
11 class JpegPixelFormatTest
extends MediaWikiMediaTestCase
{
13 protected function setUp() {
18 * Mark this test as creating thumbnail files.
20 protected function createsThumbnails() {
26 * @dataProvider providePixelFormats
27 * @covers BitmapHandler::imageMagickSubsampling
29 public function testPixelFormatRendering( $sourceFile, $pixelFormat, $samplingFactor ) {
30 global $wgUseImageMagick, $wgUseImageResize;
31 if ( !$wgUseImageMagick ) {
32 $this->markTestSkipped( "This test is only applicable when using ImageMagick thumbnailing" );
34 if ( !$wgUseImageResize ) {
35 $this->markTestSkipped( "This test is only applicable when using thumbnailing" );
38 $fmtStr = var_export( $pixelFormat, true );
39 $this->setMwGlobals( 'wgJpegPixelFormat', $pixelFormat );
41 $file = $this->dataFile( $sourceFile, 'image/jpeg' );
46 $thumb = $file->transform( $params, File
::RENDER_NOW | File
::RENDER_FORCE
);
47 $this->assertTrue( !$thumb->isError(), "created JPEG thumbnail for pixel format $fmtStr" );
49 $path = $thumb->getLocalCopyPath();
50 $this->assertTrue( is_string( $path ), "path returned for JPEG thumbnail for $fmtStr" );
52 $result = Shell
::command( 'identify',
54 '%[jpeg:sampling-factor]',
57 $this->assertEquals( 0,
58 $result->getExitCode(),
59 "ImageMagick's identify command should return success"
62 $expected = $samplingFactor;
63 $actual = trim( $result->getStdout() );
67 "IM identify expects JPEG chroma subsampling \"$expected\" for $fmtStr"
71 public static function providePixelFormats() {
73 // From 4:4:4 source file
94 // From 4:2:0 source file