diff --git a/src/Drivers/Abstract/AbstractImage.php b/src/Drivers/Abstract/AbstractImage.php index df736482..1556c451 100644 --- a/src/Drivers/Abstract/AbstractImage.php +++ b/src/Drivers/Abstract/AbstractImage.php @@ -94,6 +94,13 @@ abstract class AbstractImage ); } + public function toPng(): EncodedImage + { + return $this->encode( + $this->resolveDriverClass('Encoders\PngEncoder') + ); + } + public function greyscale(): ImageInterface { return $this->modify( diff --git a/src/Drivers/Gd/Encoders/PngEncoder.php b/src/Drivers/Gd/Encoders/PngEncoder.php new file mode 100644 index 00000000..f93afb39 --- /dev/null +++ b/src/Drivers/Gd/Encoders/PngEncoder.php @@ -0,0 +1,20 @@ +getBuffered(function () use ($image) { + imagepng($image->getFrames()->first()->getCore()); + }); + + return new EncodedImage($data, 'image/png'); + } +} diff --git a/src/Drivers/Imagick/Encoders/PngEncoder.php b/src/Drivers/Imagick/Encoders/PngEncoder.php new file mode 100644 index 00000000..8bdc03e6 --- /dev/null +++ b/src/Drivers/Imagick/Encoders/PngEncoder.php @@ -0,0 +1,26 @@ +getFrames()->first()->getCore(); + $imagick->setFormat($format); + $imagick->setImageFormat($format); + $imagick->setCompression($compression); + $imagick->setImageCompression($compression); + + return new EncodedImage($imagick->getImagesBlob(), 'image/png'); + } +}