Files
skjnldsv 6dad04eed1 feat(preview): generate previews for JPEG 2000 images
A .jp2 is typed correctly on upload and has been since 12.0.0.14, and
then nothing can render it: no provider claims image/jp2, no browser
decodes the format, so the file opens to nothing.

ImageMagick reads it where it was built with OpenJPEG, which is what the
other formats libgd cannot read already rely on, and the signature box a
.jp2 opens with sits at offset 0 where Bitmap looks for it. So this is
the same shape as TIFF: a Bitmap subclass naming the format, off until
an admin enables it.

libgd is not an option here and never was. It has no JPEG 2000 functions
at all, which is why the case for it in OC\Image sits commented out
beside the other formats it cannot read. Imaginary answers 406 for one.

The pixel assertion the AVIF tests use is not about AVIF, so it loses
the name and is shared.

Assisted-by: ClaudeCode:claude-opus-5
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
2026-09-20 23:39:37 +02:00

57 lines
1.6 KiB
PHP

<?php
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Preview;
use OC\Preview\AVIF;
use OCP\Image;
/**
* Class AVIFTest
*
* @package Test\Preview
*/
#[\PHPUnit\Framework\Attributes\Group('DB')]
class AVIFTest extends Provider {
use PreviewPixelsTrait;
#[\Override]
protected function setUp(): void {
$fileName = 'testimage.avif';
$sourcePath = \OC::$SERVERROOT . '/tests/data/' . $fileName;
// Reading an AVIF takes more than a libgd built against libavif.
// OC\Image picks its decoder from exif_imagetype(), and guards it
// with getimagesize(), so a build where either does not know the
// format never reaches imagecreatefromavif() however capable libgd
// is. Ask for the whole path rather than for one part of it, and
// say which part was missing when it is not there.
$probe = new Image();
$probe->loadFromFile($sourcePath);
if (!$probe->valid()) {
$this->markTestSkipped(sprintf(
'libgd cannot read AVIF here (IMG_AVIF=%s, exif_imagetype=%s, getimagesize type=%s, imagecreatefromavif=%s). Skipping tests',
(imagetypes() & IMG_AVIF) ? 'yes' : 'no',
var_export(@exif_imagetype($sourcePath), true),
var_export(@getimagesize($sourcePath)[2] ?? false, true),
@imagecreatefromavif($sourcePath) === false ? 'failed' : 'ok',
));
}
parent::setUp();
$this->imgPath = $this->prepareTestFile($fileName, $sourcePath);
$this->width = 1680;
$this->height = 1050;
$this->provider = new AVIF();
}
public function testPreviewCarriesThePicture(): void {
$this->assertPreviewShowsThePicture();
}
}