MediaWiki REL1_33
JpegPixelFormatTest.php
Go to the documentation of this file.
1<?php
2
4
12
13 protected function setUp() {
14 parent::setUp();
15 }
16
20 protected function createsThumbnails() {
21 return true;
22 }
23
29 public function testPixelFormatRendering( $sourceFile, $pixelFormat, $samplingFactor ) {
31 if ( !$wgUseImageMagick ) {
32 $this->markTestSkipped( "This test is only applicable when using ImageMagick thumbnailing" );
33 }
34 if ( !$wgUseImageResize ) {
35 $this->markTestSkipped( "This test is only applicable when using thumbnailing" );
36 }
37
38 $fmtStr = var_export( $pixelFormat, true );
39 $this->setMwGlobals( 'wgJpegPixelFormat', $pixelFormat );
40
41 $file = $this->dataFile( $sourceFile, 'image/jpeg' );
42
43 $params = [
44 'width' => 320,
45 ];
46 $thumb = $file->transform( $params, File::RENDER_NOW | File::RENDER_FORCE );
47 $this->assertTrue( !$thumb->isError(), "created JPEG thumbnail for pixel format $fmtStr" );
48
49 $path = $thumb->getLocalCopyPath();
50 $this->assertTrue( is_string( $path ), "path returned for JPEG thumbnail for $fmtStr" );
51
52 $result = Shell::command( 'identify',
53 '-format',
54 '%[jpeg:sampling-factor]',
55 $path
56 )->execute();
57 $this->assertEquals( 0,
58 $result->getExitCode(),
59 "ImageMagick's identify command should return success"
60 );
61
62 $expected = $samplingFactor;
63 $actual = trim( $result->getStdout() );
64 $this->assertEquals(
65 $expected,
66 $actual,
67 "IM identify expects JPEG chroma subsampling \"$expected\" for $fmtStr"
68 );
69 }
70
71 public static function providePixelFormats() {
72 return [
73 // From 4:4:4 source file
74 [
75 'yuv444.jpg',
76 false,
77 '1x1,1x1,1x1'
78 ],
79 [
80 'yuv444.jpg',
81 'yuv444',
82 '1x1,1x1,1x1'
83 ],
84 [
85 'yuv444.jpg',
86 'yuv422',
87 '2x1,1x1,1x1'
88 ],
89 [
90 'yuv444.jpg',
91 'yuv420',
92 '2x2,1x1,1x1'
93 ],
94 // From 4:2:0 source file
95 [
96 'yuv420.jpg',
97 false,
98 '2x2,1x1,1x1'
99 ],
100 [
101 'yuv420.jpg',
102 'yuv444',
103 '1x1,1x1,1x1'
104 ],
105 [
106 'yuv420.jpg',
107 'yuv422',
108 '2x1,1x1,1x1'
109 ],
110 [
111 'yuv420.jpg',
112 'yuv420',
113 '2x2,1x1,1x1'
114 ]
115 ];
116 }
117}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
$wgUseImageResize
Whether to enable server-side image thumbnailing.
$wgUseImageMagick
Resizing can be done using PHP's internal image libraries or using ImageMagick or another third-party...
const RENDER_NOW
Force rendering in the current process.
Definition File.php:60
const RENDER_FORCE
Force rendering even if thumbnail already exist and using RENDER_NOW I.e.
Definition File.php:65
Tests related to JPEG chroma subsampling via $wgJpegPixelFormat setting.
createsThumbnails()
Mark this test as creating thumbnail files.
testPixelFormatRendering( $sourceFile, $pixelFormat, $samplingFactor)
providePixelFormats BitmapHandler::imageMagickSubsampling
Specificly for testing Media handlers.
dataFile( $name, $type=false)
Utility function: Get a new file object for a file on disk but not actually in db.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Executes shell commands.
Definition Shell.php:44
$params