-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8eb1394
commit af2ee6c
Showing
8 changed files
with
134 additions
and
2 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
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
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,25 @@ | ||
<?php | ||
|
||
namespace Intervention\Image\Drivers\Gd\Encoders; | ||
|
||
use Intervention\Image\Drivers\Abstract\Encoders\AbstractEncoder; | ||
use Intervention\Image\EncodedImage; | ||
use Intervention\Image\Interfaces\EncoderInterface; | ||
use Intervention\Image\Interfaces\ImageInterface; | ||
|
||
class AvifEncoder extends AbstractEncoder implements EncoderInterface | ||
{ | ||
public function __construct(int $quality) | ||
{ | ||
$this->quality = $quality; | ||
} | ||
|
||
public function encode(ImageInterface $image): EncodedImage | ||
{ | ||
$data = $this->getBuffered(function () use ($image) { | ||
imageavif($image->getFrame()->getCore(), null, $this->quality); | ||
}); | ||
|
||
return new EncodedImage($data, 'image/avif'); | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
namespace Intervention\Image\Drivers\Imagick\Encoders; | ||
|
||
use Imagick; | ||
use Intervention\Image\Drivers\Abstract\Encoders\AbstractEncoder; | ||
use Intervention\Image\EncodedImage; | ||
use Intervention\Image\Interfaces\EncoderInterface; | ||
use Intervention\Image\Interfaces\ImageInterface; | ||
|
||
class AvifEncoder extends AbstractEncoder implements EncoderInterface | ||
{ | ||
public function encode(ImageInterface $image): EncodedImage | ||
{ | ||
$format = 'avif'; | ||
$compression = Imagick::COMPRESSION_ZIP; | ||
|
||
$imagick = $image->getFrame()->getCore(); | ||
$imagick->setFormat($format); | ||
$imagick->setImageFormat($format); | ||
$imagick->setCompression($compression); | ||
$imagick->setImageCompression($compression); | ||
|
||
return new EncodedImage($imagick->getImagesBlob(), 'image/avif'); | ||
} | ||
} |
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 | ||
|
||
namespace Intervention\Image\Tests\Drivers\Gd\Encoders; | ||
|
||
use Intervention\Image\Collection; | ||
use Intervention\Image\Drivers\Gd\Encoders\AvifEncoder; | ||
use Intervention\Image\Drivers\Gd\Frame; | ||
use Intervention\Image\Drivers\Gd\Image; | ||
use Intervention\Image\Tests\TestCase; | ||
use Intervention\MimeSniffer\MimeSniffer; | ||
use Intervention\MimeSniffer\Types\ImageAvif; | ||
|
||
/** | ||
* @requires extension gd | ||
* @covers \Intervention\Image\Drivers\Gd\Encoders\AvifEncoder | ||
*/ | ||
class AvifEncoderTest extends TestCase | ||
{ | ||
protected function getTestImage(): Image | ||
{ | ||
return new Image(new Collection([ | ||
new Frame(imagecreatetruecolor(3, 2)) | ||
])); | ||
} | ||
|
||
public function testEncode(): void | ||
{ | ||
$image = $this->getTestImage(); | ||
$encoder = new AvifEncoder(10); | ||
$result = $encoder->encode($image); | ||
$this->assertTrue(MimeSniffer::createFromString($result)->matches(new ImageAvif())); | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
namespace Intervention\Image\Tests\Drivers\Imagick\Encoders; | ||
|
||
use Imagick; | ||
use ImagickPixel; | ||
use Intervention\Image\Drivers\Imagick\Encoders\AvifEncoder; | ||
use Intervention\Image\Drivers\Imagick\Image; | ||
use Intervention\Image\Tests\TestCase; | ||
use Intervention\MimeSniffer\MimeSniffer; | ||
use Intervention\MimeSniffer\Types\ImageAvif; | ||
|
||
/** | ||
* @requires extension imagick | ||
* @covers \Intervention\Image\Drivers\Imagick\Encoders\JpegEncoder | ||
*/ | ||
class AvifEncoderTest extends TestCase | ||
{ | ||
protected function getTestImage(): Image | ||
{ | ||
$imagick = new Imagick(); | ||
$imagick->newImage(3, 2, new ImagickPixel('red'), 'png'); | ||
|
||
return new Image($imagick); | ||
} | ||
|
||
public function testEncode(): void | ||
{ | ||
$image = $this->getTestImage(); | ||
$encoder = new AvifEncoder(10); | ||
$result = $encoder->encode($image); | ||
$this->assertTrue(MimeSniffer::createFromString($result)->matches(new ImageAvif())); | ||
} | ||
} |