mirror of
https://github.com/Intervention/image.git
synced 2025-08-30 09:10:21 +02:00
Merge branch 'feature/jpeg2000'
This commit is contained in:
33
src/Drivers/Imagick/Encoders/Jpeg2000Encoder.php
Normal file
33
src/Drivers/Imagick/Encoders/Jpeg2000Encoder.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Intervention\Image\Drivers\Imagick\Encoders;
|
||||||
|
|
||||||
|
use Imagick;
|
||||||
|
use Intervention\Image\Drivers\DriverSpecializedEncoder;
|
||||||
|
use Intervention\Image\EncodedImage;
|
||||||
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
|
use Intervention\Image\Interfaces\EncodedImageInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property int $quality
|
||||||
|
*/
|
||||||
|
class Jpeg2000Encoder extends DriverSpecializedEncoder
|
||||||
|
{
|
||||||
|
public function encode(ImageInterface $image): EncodedImageInterface
|
||||||
|
{
|
||||||
|
$format = 'jp2';
|
||||||
|
$compression = Imagick::COMPRESSION_JPEG;
|
||||||
|
|
||||||
|
$imagick = $image->core()->native();
|
||||||
|
$imagick->setImageBackgroundColor('white');
|
||||||
|
$imagick->setBackgroundColor('white');
|
||||||
|
$imagick->setFormat($format);
|
||||||
|
$imagick->setImageFormat($format);
|
||||||
|
$imagick->setCompression($compression);
|
||||||
|
$imagick->setImageCompression($compression);
|
||||||
|
$imagick->setCompressionQuality($this->quality);
|
||||||
|
$imagick->setImageCompressionQuality($this->quality);
|
||||||
|
|
||||||
|
return new EncodedImage($imagick->getImagesBlob(), 'image/jp2');
|
||||||
|
}
|
||||||
|
}
|
10
src/Encoders/Jpeg2000Encoder.php
Normal file
10
src/Encoders/Jpeg2000Encoder.php
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Intervention\Image\Encoders;
|
||||||
|
|
||||||
|
class Jpeg2000Encoder extends AbstractEncoder
|
||||||
|
{
|
||||||
|
public function __construct(public int $quality = 75)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@@ -17,6 +17,7 @@ use Intervention\Image\Encoders\BmpEncoder;
|
|||||||
use Intervention\Image\Encoders\FileExtensionEncoder;
|
use Intervention\Image\Encoders\FileExtensionEncoder;
|
||||||
use Intervention\Image\Encoders\FilePathEncoder;
|
use Intervention\Image\Encoders\FilePathEncoder;
|
||||||
use Intervention\Image\Encoders\GifEncoder;
|
use Intervention\Image\Encoders\GifEncoder;
|
||||||
|
use Intervention\Image\Encoders\Jpeg2000Encoder;
|
||||||
use Intervention\Image\Encoders\JpegEncoder;
|
use Intervention\Image\Encoders\JpegEncoder;
|
||||||
use Intervention\Image\Encoders\MediaTypeEncoder;
|
use Intervention\Image\Encoders\MediaTypeEncoder;
|
||||||
use Intervention\Image\Encoders\PngEncoder;
|
use Intervention\Image\Encoders\PngEncoder;
|
||||||
@@ -812,6 +813,27 @@ final class Image implements ImageInterface, Countable
|
|||||||
return $this->toJpeg($quality);
|
return $this->toJpeg($quality);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @see ImageInterface::toJpeg()
|
||||||
|
*/
|
||||||
|
public function toJpeg2000(int $quality = 75): EncodedImageInterface
|
||||||
|
{
|
||||||
|
return $this->encode(new Jpeg2000Encoder($quality));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ALias of self::toJpeg2000()
|
||||||
|
*
|
||||||
|
* @param int $quality
|
||||||
|
* @return EncodedImageInterface
|
||||||
|
*/
|
||||||
|
public function toJp2(int $quality = 75): EncodedImageInterface
|
||||||
|
{
|
||||||
|
return $this->toJpeg2000($quality);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*
|
*
|
||||||
|
@@ -603,6 +603,14 @@ interface ImageInterface extends IteratorAggregate, Countable
|
|||||||
*/
|
*/
|
||||||
public function toJpeg(int $quality = 75): EncodedImageInterface;
|
public function toJpeg(int $quality = 75): EncodedImageInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encode image to Jpeg2000 format
|
||||||
|
*
|
||||||
|
* @param int $quality
|
||||||
|
* @return EncodedImageInterface
|
||||||
|
*/
|
||||||
|
public function toJpeg2000(int $quality = 75): EncodedImageInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encode image to Webp format
|
* Encode image to Webp format
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user