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
92c37c5
commit b5e31e5
Showing
10 changed files
with
126 additions
and
126 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,60 @@ | ||
<?php | ||
|
||
namespace Intervention\Image\Drivers\Gd\Modifiers; | ||
|
||
use Intervention\Image\Interfaces\ImageInterface; | ||
use Intervention\Image\Interfaces\ModifierInterface; | ||
|
||
class LimitColorsModifier implements ModifierInterface | ||
{ | ||
public function __construct(protected int $limit = 0, protected int $threshold = 256) | ||
{ | ||
// | ||
} | ||
|
||
public function apply(ImageInterface $image): ImageInterface | ||
{ | ||
// no color limit: no reduction | ||
if ($this->limit === 0) { | ||
return $image; | ||
} | ||
|
||
// limit is over threshold: no reduction | ||
if ($this->limit > $this->threshold) { | ||
return $image; | ||
} | ||
|
||
$width = $image->width(); | ||
$height = $image->height(); | ||
|
||
foreach ($image as $frame) { | ||
// create empty gd | ||
$reduced = imagecreatetruecolor($width, $height); | ||
|
||
// create matte | ||
$matte = imagecolorallocatealpha($reduced, 255, 255, 255, 127); | ||
|
||
// fill with matte | ||
imagefill($reduced, 0, 0, $matte); | ||
|
||
imagealphablending($reduced, false); | ||
|
||
// set transparency and get transparency index | ||
imagecolortransparent($reduced, $matte); | ||
|
||
// copy original image | ||
imagecopy($reduced, $frame->core(), 0, 0, 0, 0, $width, $height); | ||
|
||
// reduce limit by one to include possible transparency in palette | ||
$limit = imagecolortransparent($frame->core()) === -1 ? $this->limit : $this->limit - 1; | ||
|
||
// decrease colors | ||
imagetruecolortopalette($reduced, true, $limit); | ||
|
||
$frame->setCore($reduced); | ||
} | ||
|
||
|
||
return $image; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,44 @@ | ||
<?php | ||
|
||
namespace Intervention\Image\Drivers\Imagick\Modifiers; | ||
|
||
use Intervention\Image\Interfaces\ImageInterface; | ||
use Intervention\Image\Interfaces\ModifierInterface; | ||
use Intervention\Image\Traits\CanCheckType; | ||
use Intervention\Image\Drivers\Imagick\Image; | ||
|
||
class LimitColorsModifier implements ModifierInterface | ||
{ | ||
use CanCheckType; | ||
|
||
public function __construct(protected int $limit = 0, protected $threshold = 256) | ||
{ | ||
// | ||
} | ||
|
||
public function apply(ImageInterface $image): ImageInterface | ||
{ | ||
// no color limit: no reduction | ||
if ($this->limit === 0) { | ||
return $image; | ||
} | ||
|
||
// limit is over threshold: no reduction | ||
if ($this->limit > $this->threshold) { | ||
return $image; | ||
} | ||
|
||
$image = $this->failIfNotClass($image, Image::class); | ||
foreach ($image->getImagick() as $core) { | ||
$core->quantizeImage( | ||
$this->limit, | ||
$core->getImageColorspace(), | ||
0, | ||
false, | ||
false | ||
); | ||
} | ||
|
||
return $image; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.