Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F2750979
JpegPixelFormatTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
JpegPixelFormatTest.php
View Options
<?php
use
MediaWiki\FileRepo\File\File
;
use
MediaWiki\MainConfigNames
;
use
MediaWiki\Shell\Shell
;
/**
* Tests related to JPEG chroma subsampling via $wgJpegPixelFormat setting.
*
* @group Media
* @group medium
*/
class
JpegPixelFormatTest
extends
MediaWikiMediaTestCase
{
/**
* Mark this test as creating thumbnail files.
* @inheritDoc
*/
protected
function
createsThumbnails
()
{
return
true
;
}
/**
* @dataProvider providePixelFormats
* @covers \BitmapHandler::imageMagickSubsampling
*/
public
function
testPixelFormatRendering
(
$sourceFile
,
$pixelFormat
,
$samplingFactor
)
{
global
$wgUseImageMagick
,
$wgUseImageResize
;
if
(
!
$wgUseImageMagick
)
{
$this
->
markTestSkipped
(
"This test is only applicable when using ImageMagick thumbnailing"
);
}
if
(
!
$wgUseImageResize
)
{
$this
->
markTestSkipped
(
"This test is only applicable when using thumbnailing"
);
}
$fmtStr
=
var_export
(
$pixelFormat
,
true
);
$this
->
overrideConfigValue
(
MainConfigNames
::
JpegPixelFormat
,
$pixelFormat
);
$file
=
$this
->
dataFile
(
$sourceFile
,
'image/jpeg'
);
$params
=
[
'width'
=>
320
,
];
$thumb
=
$file
->
transform
(
$params
,
File
::
RENDER_NOW
|
File
::
RENDER_FORCE
);
$this
->
assertTrue
(
!
$thumb
->
isError
(),
"created JPEG thumbnail for pixel format $fmtStr"
);
$path
=
$thumb
->
getLocalCopyPath
();
$this
->
assertIsString
(
$path
,
"path returned for JPEG thumbnail for $fmtStr"
);
$result
=
Shell
::
command
(
'identify'
,
'-format'
,
'%[jpeg:sampling-factor]'
,
$path
)->
execute
();
$this
->
assertSame
(
0
,
$result
->
getExitCode
(),
"ImageMagick's identify command should return success"
);
$expected
=
$samplingFactor
;
$actual
=
trim
(
$result
->
getStdout
()
);
$this
->
assertEquals
(
$expected
,
$actual
,
"IM identify expects JPEG chroma subsampling
\"
$expected
\"
for $fmtStr"
);
}
public
static
function
providePixelFormats
()
{
return
[
// From 4:4:4 source file
[
'yuv444.jpg'
,
false
,
'1x1,1x1,1x1'
],
[
'yuv444.jpg'
,
'yuv444'
,
'1x1,1x1,1x1'
],
[
'yuv444.jpg'
,
'yuv422'
,
'2x1,1x1,1x1'
],
[
'yuv444.jpg'
,
'yuv420'
,
'2x2,1x1,1x1'
],
// From 4:2:0 source file
[
'yuv420.jpg'
,
false
,
'2x2,1x1,1x1'
],
[
'yuv420.jpg'
,
'yuv444'
,
'1x1,1x1,1x1'
],
[
'yuv420.jpg'
,
'yuv422'
,
'2x1,1x1,1x1'
],
[
'yuv420.jpg'
,
'yuv420'
,
'2x2,1x1,1x1'
]
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Jul 3, 17:36 (11 h, 16 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
1f/2e/f23112df71d7c37d6567aab76115
Default Alt Text
JpegPixelFormatTest.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment