mirror of
https://github.com/Intervention/image.git
synced 2025-08-19 12:11:26 +02:00
Add toWebp() method to ImageInterface & AbstractImage
This commit is contained in:
@@ -4,9 +4,7 @@ namespace Intervention\Image\Drivers\Abstract;
|
||||
|
||||
use Intervention\Image\Collection;
|
||||
use Intervention\Image\EncodedImage;
|
||||
use Intervention\Image\Exceptions\NotWritableException;
|
||||
use Intervention\Image\Geometry\Point;
|
||||
use Intervention\Image\Geometry\Resizer;
|
||||
use Intervention\Image\Geometry\Size;
|
||||
use Intervention\Image\Interfaces\EncoderInterface;
|
||||
use Intervention\Image\Interfaces\FrameInterface;
|
||||
@@ -92,6 +90,13 @@ abstract class AbstractImage
|
||||
);
|
||||
}
|
||||
|
||||
public function toWebp(int $quality = 75): EncodedImage
|
||||
{
|
||||
return $this->encode(
|
||||
$this->resolveDriverClass('Encoders\WebpEncoder', $quality)
|
||||
);
|
||||
}
|
||||
|
||||
public function toGif(): EncodedImage
|
||||
{
|
||||
return $this->encode(
|
||||
|
@@ -4,9 +4,6 @@ namespace Intervention\Image\Interfaces;
|
||||
|
||||
use Intervention\Image\Collection;
|
||||
use Intervention\Image\EncodedImage;
|
||||
use Intervention\Image\Interfaces\FrameInterface;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
use Intervention\Image\Interfaces\SizeInterface;
|
||||
|
||||
interface ImageInterface
|
||||
{
|
||||
@@ -21,6 +18,7 @@ interface ImageInterface
|
||||
public function modify(ModifierInterface $modifier): ImageInterface;
|
||||
public function encode(EncoderInterface $encoder): EncodedImage;
|
||||
public function toJpeg(int $quality = 75): EncodedImage;
|
||||
public function toWebp(int $quality = 75): EncodedImage;
|
||||
public function toGif(): EncodedImage;
|
||||
public function toPng(): EncodedImage;
|
||||
public function pickColors(int $x, int $y): Collection;
|
||||
|
@@ -3,7 +3,6 @@
|
||||
namespace Intervention\Image\Tests;
|
||||
|
||||
use Intervention\Image\Collection;
|
||||
use Intervention\Image\Drivers\Abstract\AbstractFrame;
|
||||
use Intervention\Image\Drivers\Abstract\AbstractImage;
|
||||
use Intervention\Image\EncodedImage;
|
||||
use Intervention\Image\Geometry\Size;
|
||||
@@ -130,13 +129,29 @@ class AbstractImageTest extends TestCase
|
||||
$encoder->shouldReceive('encode')->with($img)->andReturn($encoded);
|
||||
|
||||
$img->shouldReceive('resolveDriverClass')
|
||||
->with('Encoders\JpegEncoder', 45)
|
||||
->andReturn($encoder);
|
||||
->with('Encoders\JpegEncoder', 45)
|
||||
->andReturn($encoder);
|
||||
|
||||
$result = $img->toJpeg(45);
|
||||
$this->assertInstanceOf(EncodedImage::class, $result);
|
||||
}
|
||||
|
||||
public function testToWebp(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
|
||||
$encoded = Mockery::mock(EncodedImage::class);
|
||||
$encoder = Mockery::mock(EncoderInterface::class);
|
||||
$encoder->shouldReceive('encode')->with($img)->andReturn($encoded);
|
||||
|
||||
$img->shouldReceive('resolveDriverClass')
|
||||
->with('Encoders\WebpEncoder', 45)
|
||||
->andReturn($encoder);
|
||||
|
||||
$result = $img->toWebp(45);
|
||||
$this->assertInstanceOf(EncodedImage::class, $result);
|
||||
}
|
||||
|
||||
public function testToGif(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
|
Reference in New Issue
Block a user