Basic JPEG2000 handler
Basic handler for JPEG2000 files. Both jp2 and jpx are supported by php's image functions. No support for: - metadata - lossy vs lossless thumbnail - bucketing - thumbor Bug: T161934 Change-Id: I1a72d4dfb034f3ae24661db515cf03b35ec18fa2
This commit is contained in:
parent
3f4a52cc57
commit
3db119428a
5 changed files with 127 additions and 0 deletions
|
|
@ -34,6 +34,7 @@ For notes on 1.36.x and older releases, see HISTORY.
|
||||||
* $wgLegacyJavaScriptGlobals was deprecated in 1.36.
|
* $wgLegacyJavaScriptGlobals was deprecated in 1.36.
|
||||||
|
|
||||||
=== New user-facing features in 1.37 ===
|
=== New user-facing features in 1.37 ===
|
||||||
|
* (T161934) MediaWiki now supports JPEG2000 files, to a limited extent.
|
||||||
* Media files uploaded server side using the importImages.php maintenance
|
* Media files uploaded server side using the importImages.php maintenance
|
||||||
script now have the "mw-server-side-upload" change tag.
|
script now have the "mw-server-side-upload" change tag.
|
||||||
* …
|
* …
|
||||||
|
|
|
||||||
|
|
@ -714,6 +714,7 @@ $wgAutoloadLocalClasses = [
|
||||||
'JobQueueRedis' => __DIR__ . '/includes/jobqueue/JobQueueRedis.php',
|
'JobQueueRedis' => __DIR__ . '/includes/jobqueue/JobQueueRedis.php',
|
||||||
'JobRunner' => __DIR__ . '/includes/jobqueue/JobRunner.php',
|
'JobRunner' => __DIR__ . '/includes/jobqueue/JobRunner.php',
|
||||||
'JobSpecification' => __DIR__ . '/includes/jobqueue/JobSpecification.php',
|
'JobSpecification' => __DIR__ . '/includes/jobqueue/JobSpecification.php',
|
||||||
|
'Jpeg2000Handler' => __DIR__ . '/includes/media/Jpeg2000Handler.php',
|
||||||
'JpegHandler' => __DIR__ . '/includes/media/JpegHandler.php',
|
'JpegHandler' => __DIR__ . '/includes/media/JpegHandler.php',
|
||||||
'JpegMetadataExtractor' => __DIR__ . '/includes/media/JpegMetadataExtractor.php',
|
'JpegMetadataExtractor' => __DIR__ . '/includes/media/JpegMetadataExtractor.php',
|
||||||
'JsonContent' => __DIR__ . '/includes/content/JsonContent.php',
|
'JsonContent' => __DIR__ . '/includes/content/JsonContent.php',
|
||||||
|
|
|
||||||
54
includes/media/Jpeg2000Handler.php
Normal file
54
includes/media/Jpeg2000Handler.php
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Handler for JPEG2000 images.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
* http://www.gnu.org/copyleft/gpl.html
|
||||||
|
*
|
||||||
|
* @file
|
||||||
|
* @ingroup Media
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler for JPEG2000 images.
|
||||||
|
* image/jp2 and image/jpx (jpeg2000 part 2)
|
||||||
|
*
|
||||||
|
* @ingroup Media
|
||||||
|
*/
|
||||||
|
class Jpeg2000Handler extends BitmapHandler {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Not all browsers support jpeg2000
|
||||||
|
*
|
||||||
|
* @param File $file
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function mustRender( $file ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render files as PNG
|
||||||
|
*
|
||||||
|
* @param string $ext
|
||||||
|
* @param string $mime
|
||||||
|
* @param array|null $params
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getThumbType( $ext, $mime, $params = null ) {
|
||||||
|
return [ 'png', 'image/png' ];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -49,6 +49,8 @@ class MediaHandlerFactory {
|
||||||
'image/vnd.djvu' => DjVuHandler::class, // official
|
'image/vnd.djvu' => DjVuHandler::class, // official
|
||||||
'image/x.djvu' => DjVuHandler::class, // compat
|
'image/x.djvu' => DjVuHandler::class, // compat
|
||||||
'image/x-djvu' => DjVuHandler::class, // compat
|
'image/x-djvu' => DjVuHandler::class, // compat
|
||||||
|
'image/jp2' => Jpeg2000Handler::class,
|
||||||
|
'image/jpx' => Jpeg2000Handler::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
/** @var LoggerInterface */
|
/** @var LoggerInterface */
|
||||||
|
|
|
||||||
69
tests/phpunit/includes/media/Jpeg2000HandlerTest.php
Normal file
69
tests/phpunit/includes/media/Jpeg2000HandlerTest.php
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Jpeg2000Handler
|
||||||
|
*/
|
||||||
|
class Jpeg2000HandlerTest extends MediaWikiIntegrationTestCase {
|
||||||
|
protected function setUp() : void {
|
||||||
|
parent::setUp();
|
||||||
|
// Allocated file for testing
|
||||||
|
$this->tempFileName = tempnam( wfTempDir(), 'JPEG2000' );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function tearDown() : void {
|
||||||
|
unlink( $this->tempFileName );
|
||||||
|
parent::tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider provideTestGetImageSize
|
||||||
|
*/
|
||||||
|
public function testGetImageSize( $path, $expectedResult ) {
|
||||||
|
$handler = new Jpeg2000Handler();
|
||||||
|
$this->assertEquals( $expectedResult, $handler->getImageSize( null, $path ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provideTestGetImageSize() {
|
||||||
|
return [
|
||||||
|
[ __DIR__ . '/../../data/media/jpeg2000-lossless.jp2', [
|
||||||
|
0 => 100,
|
||||||
|
1 => 100,
|
||||||
|
2 => 10,
|
||||||
|
3 => 'width="100" height="100"',
|
||||||
|
'bits' => 8,
|
||||||
|
'channels' => 3,
|
||||||
|
'mime' => 'image/jp2'
|
||||||
|
] ],
|
||||||
|
[ __DIR__ . '/../../data/media/jpeg2000-lossy.jp2', [
|
||||||
|
0 => 100,
|
||||||
|
1 => 100,
|
||||||
|
2 => 10,
|
||||||
|
3 => 'width="100" height="100"',
|
||||||
|
'bits' => 8,
|
||||||
|
'channels' => 3,
|
||||||
|
'mime' => 'image/jp2'
|
||||||
|
] ],
|
||||||
|
[ __DIR__ . '/../../data/media/jpeg2000-alpha.jp2', [
|
||||||
|
0 => 100,
|
||||||
|
1 => 100,
|
||||||
|
2 => 10,
|
||||||
|
3 => 'width="100" height="100"',
|
||||||
|
'bits' => 8,
|
||||||
|
'channels' => 4,
|
||||||
|
'mime' => 'image/jp2'
|
||||||
|
] ],
|
||||||
|
[ __DIR__ . '/../../data/media/jpeg2000-profile.jpf', [
|
||||||
|
0 => 100,
|
||||||
|
1 => 100,
|
||||||
|
2 => 10,
|
||||||
|
3 => 'width="100" height="100"',
|
||||||
|
'bits' => 8,
|
||||||
|
'channels' => 4,
|
||||||
|
'mime' => 'image/jp2'
|
||||||
|
] ],
|
||||||
|
|
||||||
|
// Error cases
|
||||||
|
[ __FILE__, false ],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue