mirror of
https://github.com/Intervention/image.git
synced 2025-09-01 18:02:45 +02:00
Refactor color allocation helper
This commit is contained in:
@@ -3,7 +3,6 @@
|
|||||||
namespace Intervention\Image\Drivers\Gd;
|
namespace Intervention\Image\Drivers\Gd;
|
||||||
|
|
||||||
use Intervention\Image\Collection;
|
use Intervention\Image\Collection;
|
||||||
use Intervention\Image\Colors\Rgb\Channels\Alpha;
|
|
||||||
use Intervention\Image\Drivers\Gd\Frame;
|
use Intervention\Image\Drivers\Gd\Frame;
|
||||||
use Intervention\Image\Drivers\Gd\Image;
|
use Intervention\Image\Drivers\Gd\Image;
|
||||||
use Intervention\Image\Drivers\Gd\Traits\CanHandleColors;
|
use Intervention\Image\Drivers\Gd\Traits\CanHandleColors;
|
||||||
@@ -11,9 +10,6 @@ use Intervention\Image\Interfaces\ColorInterface;
|
|||||||
use Intervention\Image\Interfaces\FactoryInterface;
|
use Intervention\Image\Interfaces\FactoryInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Traits\CanHandleInput;
|
use Intervention\Image\Traits\CanHandleInput;
|
||||||
use Intervention\Image\Colors\Rgb\Channels\Blue;
|
|
||||||
use Intervention\Image\Colors\Rgb\Channels\Green;
|
|
||||||
use Intervention\Image\Colors\Rgb\Channels\Red;
|
|
||||||
|
|
||||||
class Factory implements FactoryInterface
|
class Factory implements FactoryInterface
|
||||||
{
|
{
|
||||||
@@ -73,19 +69,7 @@ class Factory implements FactoryInterface
|
|||||||
|
|
||||||
$color = match (is_null($background)) {
|
$color = match (is_null($background)) {
|
||||||
true => imagecolorallocatealpha($core, 255, 0, 255, 127),
|
true => imagecolorallocatealpha($core, 255, 0, 255, 127),
|
||||||
default => imagecolorallocatealpha(
|
default => $this->allocateColor($core, $background),
|
||||||
$core,
|
|
||||||
$background->channel(Red::class)->value(),
|
|
||||||
$background->channel(Green::class)->value(),
|
|
||||||
$background->channel(Blue::class)->value(),
|
|
||||||
$this->convertRange(
|
|
||||||
$background->channel(Alpha::class)->value(),
|
|
||||||
0,
|
|
||||||
255,
|
|
||||||
127,
|
|
||||||
0
|
|
||||||
)
|
|
||||||
),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
imagefill($core, 0, 0, $color);
|
imagefill($core, 0, 0, $color);
|
||||||
|
@@ -2,10 +2,34 @@
|
|||||||
|
|
||||||
namespace Intervention\Image\Drivers\Gd\Traits;
|
namespace Intervention\Image\Drivers\Gd\Traits;
|
||||||
|
|
||||||
|
use GdImage;
|
||||||
use Intervention\Image\Colors\Rgb\Color;
|
use Intervention\Image\Colors\Rgb\Color;
|
||||||
|
use Intervention\Image\Interfaces\ColorInterface;
|
||||||
|
use Intervention\Image\Colors\Rgb\Channels\Alpha;
|
||||||
|
use Intervention\Image\Colors\Rgb\Channels\Blue;
|
||||||
|
use Intervention\Image\Colors\Rgb\Channels\Green;
|
||||||
|
use Intervention\Image\Colors\Rgb\Channels\Red;
|
||||||
|
|
||||||
trait CanHandleColors
|
trait CanHandleColors
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Allocate given color in given gd image and return color value/index
|
||||||
|
*
|
||||||
|
* @param GdImage $gd
|
||||||
|
* @param ColorInterface $color
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
protected function allocateColor(GdImage $gd, ColorInterface $color): int
|
||||||
|
{
|
||||||
|
return imagecolorallocatealpha(
|
||||||
|
$gd,
|
||||||
|
$color->channel(Red::class)->value(),
|
||||||
|
$color->channel(Green::class)->value(),
|
||||||
|
$color->channel(Blue::class)->value(),
|
||||||
|
$this->convertRange($color->channel(Alpha::class)->value(), 0, 255, 127, 0)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms array result from imagecolorsforindex() to Color object
|
* Transforms array result from imagecolorsforindex() to Color object
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user