Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F2750573
WebPHandlerTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
10 KB
Referenced Files
None
Subscribers
None
WebPHandlerTest.php
View Options
<?php
/**
* @covers \WebPHandler
*/
class
WebPHandlerTest
extends
MediaWikiIntegrationTestCase
{
/**
* @dataProvider provideTestExtractMetaData
*/
public
function
testExtractMetaData
(
$header
,
$expectedResult
)
{
$tempFileName
=
$this
->
getNewTempFile
();
// Put header into file
file_put_contents
(
$tempFileName
,
$header
);
$this
->
assertEquals
(
$expectedResult
,
WebPHandler
::
extractMetadata
(
$tempFileName
)
);
}
public
static
function
provideTestExtractMetaData
()
{
return
[
// Files from https://developers.google.com/speed/webp/gallery2
[
"
\x
52
\x
49
\x
46
\x
46
\x
90
\x
68
\x
01
\x
00
\x
57
\x
45
\x
42
\x
50
\x
56
\x
50
\x
38
\x
4C
\x
83
\x
68
\x
01
\x
00
\x
2F
\x
8F
\x
01
\x
4B
\x
10
\x
8D
\x
38
\x
6C
\x
DB
\x
46
\x
92
\x
E0
\x
E0
\x
82
\x
7B
\x
6C"
,
[
'compression'
=>
'lossless'
,
'width'
=>
400
,
'height'
=>
301
]
],
[
"
\x
52
\x
49
\x
46
\x
46
\x
64
\x
5B
\x
00
\x
00
\x
57
\x
45
\x
42
\x
50
\x
56
\x
50
\x
38
\x
58
\x
0A
\x
00
\x
00
\x
00
\x
10
\x
00
\x
00
\x
00
\x
8F
\x
01
\x
00
\x
2C
\x
01
\x
00
\x
41
\x
4C
\x
50
\x
48
\x
E5
\x
0E"
,
[
'compression'
=>
'unknown'
,
'animated'
=>
false
,
'transparency'
=>
true
,
'width'
=>
400
,
'height'
=>
301
]
],
[
"
\x
52
\x
49
\x
46
\x
46
\x
A8
\x
72
\x
00
\x
00
\x
57
\x
45
\x
42
\x
50
\x
56
\x
50
\x
38
\x
4C
\x
9B
\x
72
\x
00
\x
00
\x
2F
\x
81
\x
81
\x
62
\x
10
\x
8D
\x
40
\x
8C
\x
24
\x
39
\x
6E
\x
73
\x
73
\x
38
\x
01
\x
96"
,
[
'compression'
=>
'lossless'
,
'width'
=>
386
,
'height'
=>
395
]
],
[
"
\x
52
\x
49
\x
46
\x
46
\x
E0
\x
42
\x
00
\x
00
\x
57
\x
45
\x
42
\x
50
\x
56
\x
50
\x
38
\x
58
\x
0A
\x
00
\x
00
\x
00
\x
10
\x
00
\x
00
\x
00
\x
81
\x
01
\x
00
\x
8A
\x
01
\x
00
\x
41
\x
4C
\x
50
\x
48
\x
56
\x
10"
,
[
'compression'
=>
'unknown'
,
'animated'
=>
false
,
'transparency'
=>
true
,
'width'
=>
386
,
'height'
=>
395
]
],
[
"
\x
52
\x
49
\x
46
\x
46
\x
70
\x
61
\x
02
\x
00
\x
57
\x
45
\x
42
\x
50
\x
56
\x
50
\x
38
\x
4C
\x
63
\x
61
\x
02
\x
00
\x
2F
\x
1F
\x
C3
\x
95
\x
10
\x
8D
\x
C8
\x
72
\x
DB
\x
C8
\x
92
\x
24
\x
D8
\x
91
\x
D9
\x
91"
,
[
'compression'
=>
'lossless'
,
'width'
=>
800
,
'height'
=>
600
]
],
[
"
\x
52
\x
49
\x
46
\x
46
\x
1C
\x
1D
\x
01
\x
00
\x
57
\x
45
\x
42
\x
50
\x
56
\x
50
\x
38
\x
58
\x
0A
\x
00
\x
00
\x
00
\x
10
\x
00
\x
00
\x
00
\x
1F
\x
03
\x
00
\x
57
\x
02
\x
00
\x
41
\x
4C
\x
50
\x
48
\x
25
\x
8B"
,
[
'compression'
=>
'unknown'
,
'animated'
=>
false
,
'transparency'
=>
true
,
'width'
=>
800
,
'height'
=>
600
]
],
[
"
\x
52
\x
49
\x
46
\x
46
\x
FA
\x
C5
\x
00
\x
00
\x
57
\x
45
\x
42
\x
50
\x
56
\x
50
\x
38
\x
4C
\x
EE
\x
C5
\x
00
\x
00
\x
2F
\x
A4
\x
81
\x
28
\x
10
\x
8D
\x
40
\x
68
\x
24
\x
C9
\x
91
\x
A4
\x
AE
\x
F3
\x
97
\x
75"
,
[
'compression'
=>
'lossless'
,
'width'
=>
421
,
'height'
=>
163
]
],
[
"
\x
52
\x
49
\x
46
\x
46
\x
F6
\x
5D
\x
00
\x
00
\x
57
\x
45
\x
42
\x
50
\x
56
\x
50
\x
38
\x
58
\x
0A
\x
00
\x
00
\x
00
\x
10
\x
00
\x
00
\x
00
\x
A4
\x
01
\x
00
\x
A2
\x
00
\x
00
\x
41
\x
4C
\x
50
\x
48
\x
38
\x
1A"
,
[
'compression'
=>
'unknown'
,
'animated'
=>
false
,
'transparency'
=>
true
,
'width'
=>
421
,
'height'
=>
163
]
],
[
"
\x
52
\x
49
\x
46
\x
46
\x
C4
\x
96
\x
01
\x
00
\x
57
\x
45
\x
42
\x
50
\x
56
\x
50
\x
38
\x
4C
\x
B8
\x
96
\x
01
\x
00
\x
2F
\x
2B
\x
C1
\x
4A
\x
10
\x
11
\x
87
\x
6D
\x
DB
\x
48
\x
12
\x
FC
\x
60
\x
B0
\x
83
\x
24"
,
[
'compression'
=>
'lossless'
,
'width'
=>
300
,
'height'
=>
300
]
],
[
"
\x
52
\x
49
\x
46
\x
46
\x
0A
\x
11
\x
01
\x
00
\x
57
\x
45
\x
42
\x
50
\x
56
\x
50
\x
38
\x
58
\x
0A
\x
00
\x
00
\x
00
\x
10
\x
00
\x
00
\x
00
\x
2B
\x
01
\x
00
\x
2B
\x
01
\x
00
\x
41
\x
4C
\x
50
\x
48
\x
67
\x
6E"
,
[
'compression'
=>
'unknown'
,
'animated'
=>
false
,
'transparency'
=>
true
,
'width'
=>
300
,
'height'
=>
300
]
],
// Lossy files from https://developers.google.com/speed/webp/gallery1
[
"
\x
52
\x
49
\x
46
\x
46
\x
68
\x
76
\x
00
\x
00
\x
57
\x
45
\x
42
\x
50
\x
56
\x
50
\x
38
\x
20
\x
5C
\x
76
\x
00
\x
00
\x
D2
\x
BE
\x
01
\x
9D
\x
01
\x
2A
\x
26
\x
02
\x
70
\x
01
\x
3E
\x
D5
\x
4E
\x
97
\x
43
\x
A2"
,
[
'compression'
=>
'lossy'
,
'width'
=>
550
,
'height'
=>
368
]
],
[
"
\x
52
\x
49
\x
46
\x
46
\x
B0
\x
EC
\x
00
\x
00
\x
57
\x
45
\x
42
\x
50
\x
56
\x
50
\x
38
\x
20
\x
A4
\x
EC
\x
00
\x
00
\x
B2
\x
4B
\x
02
\x
9D
\x
01
\x
2A
\x
26
\x
02
\x
94
\x
01
\x
3E
\x
D1
\x
50
\x
96
\x
46
\x
26"
,
[
'compression'
=>
'lossy'
,
'width'
=>
550
,
'height'
=>
404
]
],
[
"
\x
52
\x
49
\x
46
\x
46
\x
7A
\x
19
\x
03
\x
00
\x
57
\x
45
\x
42
\x
50
\x
56
\x
50
\x
38
\x
20
\x
6E
\x
19
\x
03
\x
00
\x
B2
\x
F8
\x
09
\x
9D
\x
01
\x
2A
\x
00
\x
05
\x
D0
\x
02
\x
3E
\x
AD
\x
46
\x
99
\x
4A
\x
A5"
,
[
'compression'
=>
'lossy'
,
'width'
=>
1280
,
'height'
=>
720
]
],
[
"
\x
52
\x
49
\x
46
\x
46
\x
44
\x
B3
\x
02
\x
00
\x
57
\x
45
\x
42
\x
50
\x
56
\x
50
\x
38
\x
20
\x
38
\x
B3
\x
02
\x
00
\x
52
\x
57
\x
06
\x
9D
\x
01
\x
2A
\x
00
\x
04
\x
04
\x
03
\x
3E
\x
A5
\x
44
\x
96
\x
49
\x
26"
,
[
'compression'
=>
'lossy'
,
'width'
=>
1024
,
'height'
=>
772
]
],
[
"
\x
52
\x
49
\x
46
\x
46
\x
02
\x
43
\x
01
\x
00
\x
57
\x
45
\x
42
\x
50
\x
56
\x
50
\x
38
\x
20
\x
F6
\x
42
\x
01
\x
00
\x
12
\x
C0
\x
05
\x
9D
\x
01
\x
2A
\x
00
\x
04
\x
F0
\x
02
\x
3E
\x
79
\x
34
\x
93
\x
47
\x
A4"
,
[
'compression'
=>
'lossy'
,
'width'
=>
1024
,
'height'
=>
752
]
],
// Animated file from https://groups.google.com/a/chromium.org/d/topic/blink-dev/Y8tRC4mdQz8/discussion
[
"
\x
52
\x
49
\x
46
\x
46
\x
D0
\x
0B
\x
02
\x
00
\x
57
\x
45
\x
42
\x
50
\x
56
\x
50
\x
38
\x
58
\x
0A
\x
00
\x
00
\x
00
\x
12
\x
00
\x
00
\x
00
\x
3F
\x
01
\x
00
\x
3F
\x
01
\x
00
\x
41
\x
4E"
,
[
'compression'
=>
'unknown'
,
'animated'
=>
true
,
'transparency'
=>
true
,
'width'
=>
320
,
'height'
=>
320
]
],
// Error cases
[
''
,
false
],
[
' '
,
false
],
[
'RIFF '
,
false
],
[
'RIFF1234WEBP '
,
false
],
[
'RIFF1234WEBPVP8 '
,
false
],
[
'RIFF1234WEBPVP8L '
,
false
],
];
// phpcs:enable
}
/**
* @dataProvider provideTestWithFileExtractMetaData
*/
public
function
testWithFileExtractMetaData
(
$filename
,
$expectedResult
)
{
$this
->
assertEquals
(
$expectedResult
,
WebPHandler
::
extractMetadata
(
$filename
)
);
}
public
static
function
provideTestWithFileExtractMetaData
()
{
return
[
[
__DIR__
.
'/../../data/media/2_webp_ll.webp'
,
[
'compression'
=>
'lossless'
,
'width'
=>
386
,
'height'
=>
395
]
],
[
__DIR__
.
'/../../data/media/2_webp_a.webp'
,
[
'compression'
=>
'lossy'
,
'animated'
=>
false
,
'transparency'
=>
true
,
'width'
=>
386
,
'height'
=>
395
]
],
];
}
/**
* @dataProvider provideTestGetSizeAndMetadata
*/
public
function
testGetSizeAndMetadata
(
$path
,
$expectedResult
)
{
$handler
=
new
WebPHandler
();
$this
->
assertEquals
(
$expectedResult
,
$handler
->
getSizeAndMetadata
(
null
,
$path
)
);
}
public
static
function
provideTestGetSizeAndMetadata
()
{
return
[
// Public domain files from https://developers.google.com/speed/webp/gallery2
[
__DIR__
.
'/../../data/media/2_webp_a.webp'
,
[
'width'
=>
386
,
'height'
=>
395
,
'metadata'
=>
[
'compression'
=>
'lossy'
,
'animated'
=>
false
,
'transparency'
=>
true
,
'width'
=>
386
,
'height'
=>
395
,
'metadata'
=>
[
'_MW_WEBP_VERSION'
=>
2
,
],
],
]
],
[
__DIR__
.
'/../../data/media/2_webp_ll.webp'
,
[
'width'
=>
386
,
'height'
=>
395
,
'metadata'
=>
[
'compression'
=>
'lossless'
,
'width'
=>
386
,
'height'
=>
395
,
'metadata'
=>
[
'_MW_WEBP_VERSION'
=>
2
,
],
],
]
],
[
__DIR__
.
'/../../data/media/webp_animated.webp'
,
[
'width'
=>
300
,
'height'
=>
225
,
'metadata'
=>
[
'compression'
=>
'unknown'
,
'animated'
=>
true
,
'transparency'
=>
true
,
'width'
=>
300
,
'height'
=>
225
,
'metadata'
=>
[
'_MW_WEBP_VERSION'
=>
2
,
],
],
]
],
[
__DIR__
.
'/../../data/media/exif.webp'
,
[
'width'
=>
40
,
'height'
=>
10
,
'metadata'
=>
[
'compression'
=>
'lossy'
,
'animated'
=>
false
,
'transparency'
=>
false
,
'width'
=>
40
,
'height'
=>
10
,
'metadata'
=>
[
'_MW_WEBP_VERSION'
=>
2
,
],
'media-metadata'
=>
[
'GPSLatitude'
=>
88.51805555555555
,
'GPSLongitude'
=>
-
21.12357
,
'GPSAltitude'
=>
-
3.1415926530119025
,
'GPSDOP'
=>
'5/1'
,
'GPSVersionID'
=>
'2.2.0.0'
]
]
]
],
// Using non-standard "Exif\0\0" prefix
[
__DIR__
.
'/../../data/media/exif-prefix.webp'
,
[
'width'
=>
40
,
'height'
=>
10
,
'metadata'
=>
[
'compression'
=>
'lossy'
,
'animated'
=>
false
,
'transparency'
=>
false
,
'width'
=>
40
,
'height'
=>
10
,
'metadata'
=>
[
'_MW_WEBP_VERSION'
=>
2
,
],
'media-metadata'
=>
[
'GPSLatitude'
=>
88.51805555555555
,
'GPSLongitude'
=>
-
21.12357
,
'GPSAltitude'
=>
-
3.1415926530119025
,
'GPSDOP'
=>
'5/1'
,
'GPSVersionID'
=>
'2.2.0.0'
]
]
]
],
// Using standard "xmp " fourcc
[
__DIR__
.
'/../../data/media/xmp.webp'
,
[
'width'
=>
420
,
'height'
=>
300
,
'metadata'
=>
[
'compression'
=>
'lossy'
,
'animated'
=>
false
,
'transparency'
=>
false
,
'width'
=>
420
,
'height'
=>
300
,
'metadata'
=>
[
'_MW_WEBP_VERSION'
=>
2
,
],
'media-metadata'
=>
[
'ImageDescription'
=>
[
'x-default'
=>
'An example image'
,
'en'
=>
'right translation'
,
'_type'
=>
'lang'
]
]
]
]
],
// Using the "xmp\0" fourcc (not standard "xmp ").
[
__DIR__
.
'/../../data/media/xmp-null.webp'
,
[
'width'
=>
420
,
'height'
=>
300
,
'metadata'
=>
[
'compression'
=>
'lossy'
,
'animated'
=>
false
,
'transparency'
=>
false
,
'width'
=>
420
,
'height'
=>
300
,
'metadata'
=>
[
'_MW_WEBP_VERSION'
=>
2
,
],
'media-metadata'
=>
[
'ImageDescription'
=>
[
'x-default'
=>
'Image with XMPnull byte fourcc'
,
'en'
=>
'right translation'
,
'_type'
=>
'lang'
]
]
]
]
],
// Containing both XMP and Exif
[
__DIR__
.
'/../../data/media/xmp-exif.webp'
,
[
'width'
=>
420
,
'height'
=>
300
,
'metadata'
=>
[
'compression'
=>
'lossy'
,
'animated'
=>
false
,
'transparency'
=>
false
,
'width'
=>
420
,
'height'
=>
300
,
'metadata'
=>
[
'_MW_WEBP_VERSION'
=>
2
,
],
'media-metadata'
=>
[
'ImageDescription'
=>
[
'x-default'
=>
'right(iptc)'
,
'en'
=>
'right translation'
,
'_type'
=>
'lang'
],
'XResolution'
=>
'72/1'
,
'YResolution'
=>
'72/1'
,
'ResolutionUnit'
=>
2
,
'YCbCrPositioning'
=>
1
,
]
]
]
],
// Lossless red square at max resolution to confirm height decoding
[
__DIR__
.
'/../../data/media/webp_ll_large.webp'
,
[
'width'
=>
16383
,
'height'
=>
16383
,
'metadata'
=>
[
'compression'
=>
'lossless'
,
'width'
=>
16383
,
'height'
=>
16383
,
'metadata'
=>
[
'_MW_WEBP_VERSION'
=>
2
,
],
],
]
],
// Error cases
[
__FILE__
,
[
'metadata'
=>
[
'_error'
=>
'0'
]
],
],
];
}
/**
* Tests the WebP MIME detection. This should really be a separate test, but sticking it
* here for now.
*
* @dataProvider provideTestGetMimeType
*/
public
function
testGuessMimeType
(
$path
)
{
$mime
=
$this
->
getServiceContainer
()->
getMimeAnalyzer
();
$this
->
assertEquals
(
'image/webp'
,
$mime
->
guessMimeType
(
$path
,
false
)
);
}
public
static
function
provideTestGetMimeType
()
{
return
[
// Public domain files from https://developers.google.com/speed/webp/gallery2
[
__DIR__
.
'/../../data/media/2_webp_a.webp'
],
[
__DIR__
.
'/../../data/media/2_webp_ll.webp'
],
[
__DIR__
.
'/../../data/media/webp_animated.webp'
],
];
}
}
/* Python code to extract a header and convert to PHP format:
* print '"%s"' % ''.implode( '\\x%02X' % ord(c) for c in urllib.urlopen(url).read(36) )
*/
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Jul 3, 16:45 (8 h, 6 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
e8/a1/52322564832fa69562e388ab4568
Default Alt Text
WebPHandlerTest.php (10 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment