-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* jpeg2000 encoder * allow image/x-jp2-codestream * Refactor mime type detection * Add BaseTestCase::assertMediaTypeJpeg2000() * Add debug info * Include alternative Jpeg 2000 magic byte signature * Revert "Add debug info" This reverts commit 5a656d3. * Reduce sample size * Refactor Jpeg200EncoderTest::class --------- Co-authored-by: Oliver Vogel <[email protected]>
- Loading branch information
1 parent
28880b2
commit ceb985c
Showing
3 changed files
with
64 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Intervention\Image\Drivers\Vips\Encoders; | ||
|
||
use Intervention\Image\EncodedImage; | ||
use Intervention\Image\Encoders\Jpeg2000Encoder as GenericJpeg2000Encoder; | ||
use Intervention\Image\Interfaces\ImageInterface; | ||
use Intervention\Image\Interfaces\SpecializedInterface; | ||
|
||
class Jpeg2000Encoder extends GenericJpeg2000Encoder implements SpecializedInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @see EncoderInterface::function() | ||
*/ | ||
public function encode(ImageInterface $image): EncodedImage | ||
{ | ||
$result = $image->core()->native()->writeToBuffer('.j2k', [ | ||
'Q' => $this->quality, | ||
'strip' => true, | ||
'lossless' => false, | ||
]); | ||
|
||
return new EncodedImage($result, 'image/jp2'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Intervention\Image\Drivers\Vips\Tests\Unit\Encoders; | ||
|
||
use Intervention\Image\Drivers\Vips\Driver; | ||
use Intervention\Image\Drivers\Vips\Encoders\Jpeg2000Encoder; | ||
use Intervention\Image\Drivers\Vips\Tests\BaseTestCase; | ||
use Intervention\Image\EncodedImage; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
|
||
#[CoversClass(Jpeg2000Encoder::class)] | ||
final class Jpeg200EncoderTest extends BaseTestCase | ||
{ | ||
public function testEncode(): void | ||
{ | ||
$image = (new Driver())->createImage(3, 2); | ||
$encoder = new Jpeg2000Encoder(75); | ||
$encoder->setDriver(new Driver()); | ||
$result = $encoder->encode($image); | ||
$this->assertEquals('image/jp2', $result->mimetype()); | ||
$this->assertTrue($this->isJpeg2000($result), 'Encoding result is not in Jpeg 2000 format.'); | ||
} | ||
|
||
private function isJpeg2000(string|EncodedImage $input): bool | ||
{ | ||
return 1 === preg_match( | ||
"/^0000000C6A5020200D0A870A|FF4FFF51/", | ||
strtoupper(substr(bin2hex((string) $input), 0, 24)) | ||
); | ||
} | ||
} |