mirror of
https://github.com/Intervention/image.git
synced 2025-08-20 12:41:23 +02:00
TransparentColorDecoder
This commit is contained in:
@@ -199,7 +199,7 @@ abstract class AbstractImage
|
||||
);
|
||||
}
|
||||
|
||||
public function pad(int $width, int $height, string $position = 'center', $backgroundColor = 'fff'): ImageInterface
|
||||
public function pad(int $width, int $height, string $position = 'center', $backgroundColor = 'transparent'): ImageInterface
|
||||
{
|
||||
// original
|
||||
$imagesize = $this->getSize();
|
||||
@@ -212,7 +212,7 @@ abstract class AbstractImage
|
||||
);
|
||||
}
|
||||
|
||||
public function padDown(int $width, int $height, string $position = 'center', $backgroundColor = 'fff'): ImageInterface
|
||||
public function padDown(int $width, int $height, string $position = 'center', $backgroundColor = 'transparent'): ImageInterface
|
||||
{
|
||||
// original
|
||||
$imagesize = $this->getSize();
|
||||
|
21
src/Drivers/Gd/Decoders/TransparentColorDecoder.php
Normal file
21
src/Drivers/Gd/Decoders/TransparentColorDecoder.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Drivers\Gd\Decoders;
|
||||
|
||||
use Intervention\Image\Drivers\Gd\Color;
|
||||
use Intervention\Image\Interfaces\ColorInterface;
|
||||
use Intervention\Image\Interfaces\DecoderInterface;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
use Intervention\Image\Traits\CanValidateColors;
|
||||
|
||||
class TransparentColorDecoder extends ArrayColorDecoder implements DecoderInterface
|
||||
{
|
||||
public function decode($input): ImageInterface|ColorInterface
|
||||
{
|
||||
if (! is_string($input) || strtolower($input) !== 'transparent') {
|
||||
$this->fail();
|
||||
}
|
||||
|
||||
return parent::decode([0, 0, 0, 0]);
|
||||
}
|
||||
}
|
@@ -11,10 +11,12 @@ class InputHandler extends AbstractInputHandler
|
||||
{
|
||||
return new Decoders\ArrayColorDecoder(
|
||||
new Decoders\HexColorDecoder(
|
||||
new Decoders\FilePathImageDecoder(
|
||||
new Decoders\BinaryImageDecoder(
|
||||
new Decoders\DataUriImageDecoder(
|
||||
new Decoders\Base64ImageDecoder()
|
||||
new Decoders\TransparentColorDecoder(
|
||||
new Decoders\FilePathImageDecoder(
|
||||
new Decoders\BinaryImageDecoder(
|
||||
new Decoders\DataUriImageDecoder(
|
||||
new Decoders\Base64ImageDecoder()
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
21
src/Drivers/Imagick/Decoders/TransparentColorDecoder.php
Normal file
21
src/Drivers/Imagick/Decoders/TransparentColorDecoder.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Drivers\Imagick\Decoders;
|
||||
|
||||
use Intervention\Image\Drivers\Imagick\Color;
|
||||
use Intervention\Image\Interfaces\ColorInterface;
|
||||
use Intervention\Image\Interfaces\DecoderInterface;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
use Intervention\Image\Traits\CanValidateColors;
|
||||
|
||||
class TransparentColorDecoder extends ArrayColorDecoder implements DecoderInterface
|
||||
{
|
||||
public function decode($input): ImageInterface|ColorInterface
|
||||
{
|
||||
if (! is_string($input) || strtolower($input) !== 'transparent') {
|
||||
$this->fail();
|
||||
}
|
||||
|
||||
return parent::decode([0, 0, 0, 0]);
|
||||
}
|
||||
}
|
@@ -11,10 +11,12 @@ class InputHandler extends AbstractInputHandler
|
||||
{
|
||||
return new Decoders\ArrayColorDecoder(
|
||||
new Decoders\HexColorDecoder(
|
||||
new Decoders\FilePathImageDecoder(
|
||||
new Decoders\BinaryImageDecoder(
|
||||
new Decoders\DataUriImageDecoder(
|
||||
new Decoders\Base64ImageDecoder()
|
||||
new Decoders\TransparentColorDecoder(
|
||||
new Decoders\FilePathImageDecoder(
|
||||
new Decoders\BinaryImageDecoder(
|
||||
new Decoders\DataUriImageDecoder(
|
||||
new Decoders\Base64ImageDecoder()
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
21
tests/Drivers/Gd/Decoders/TransparentColorDecoderTest.php
Normal file
21
tests/Drivers/Gd/Decoders/TransparentColorDecoderTest.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Tests\Drivers\Gd\Decoders;
|
||||
|
||||
use Intervention\Image\Drivers\Gd\Color;
|
||||
use Intervention\Image\Drivers\Gd\Decoders\TransparentColorDecoder;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
|
||||
class TransparentColorDecoderTest extends TestCase
|
||||
{
|
||||
public function testDecode(): void
|
||||
{
|
||||
$decoder = new TransparentColorDecoder();
|
||||
$color = $decoder->decode('transparent');
|
||||
$this->assertInstanceOf(Color::class, $color);
|
||||
$this->assertEquals(0, $color->red());
|
||||
$this->assertEquals(0, $color->green());
|
||||
$this->assertEquals(0, $color->blue());
|
||||
$this->assertEquals(0, $color->alpha());
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Tests\Drivers\Imagick\Decoders;
|
||||
|
||||
use Intervention\Image\Drivers\Imagick\Color;
|
||||
use Intervention\Image\Drivers\Imagick\Decoders\TransparentColorDecoder;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
|
||||
class TransparentColorDecoderTest extends TestCase
|
||||
{
|
||||
public function testDecode(): void
|
||||
{
|
||||
$decoder = new TransparentColorDecoder();
|
||||
$color = $decoder->decode('transparent');
|
||||
$this->assertInstanceOf(Color::class, $color);
|
||||
$this->assertEquals(0, $color->red());
|
||||
$this->assertEquals(0, $color->green());
|
||||
$this->assertEquals(0, $color->blue());
|
||||
$this->assertEquals(0, $color->alpha());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user