mirror of
https://github.com/Intervention/image.git
synced 2025-08-31 01:29:51 +02:00
Refactoring
This commit is contained in:
@@ -18,6 +18,12 @@ abstract class AbstractImage
|
||||
use CanResolveDriverClass;
|
||||
|
||||
protected $loops = 0;
|
||||
protected $frames;
|
||||
|
||||
public function __construct(Collection $frames)
|
||||
{
|
||||
$this->frames = $frames;
|
||||
}
|
||||
|
||||
public function getIterator(): Collection
|
||||
{
|
||||
@@ -70,11 +76,22 @@ abstract class AbstractImage
|
||||
|
||||
public function toJpeg(?int $quality = null): string
|
||||
{
|
||||
return $this->encode($this->resolveDriverClass('Encoders\JpegEncoder', $quality));
|
||||
return $this->encode(
|
||||
$this->resolveDriverClass('Encoders\JpegEncoder', $quality)
|
||||
);
|
||||
}
|
||||
|
||||
public function toGif(): string
|
||||
{
|
||||
return $this->encode($this->resolveDriverClass('Encoders\GifEncoder'));
|
||||
return $this->encode(
|
||||
$this->resolveDriverClass('Encoders\GifEncoder')
|
||||
);
|
||||
}
|
||||
|
||||
public function greyscale(): ImageInterface
|
||||
{
|
||||
return $this->modify(
|
||||
$this->resolveDriverClass('Modifiers\GreyscaleModifier')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -40,12 +40,13 @@ class BinaryImageDecoder extends AbstractDecoder implements DecoderInterface
|
||||
$image = new Image(new Collection());
|
||||
$gif = GifDecoder::decode($input);
|
||||
|
||||
$image->setLoops($gif->getMainApplicationExtension()?->getLoops());
|
||||
|
||||
if (!$gif->isAnimated()) {
|
||||
return $image->addFrame(new Frame(@imagecreatefromstring($input)));
|
||||
}
|
||||
|
||||
$image->setLoops($gif->getMainApplicationExtension()?->getLoops());
|
||||
|
||||
$splitter = GifSplitter::create($gif)->split();
|
||||
$delays = $splitter->getDelays();
|
||||
foreach ($splitter->coalesceToResources() as $key => $gd) {
|
||||
|
@@ -14,13 +14,6 @@ use IteratorAggregate;
|
||||
|
||||
class Image extends AbstractImage implements ImageInterface, IteratorAggregate
|
||||
{
|
||||
protected $loops = 0;
|
||||
|
||||
public function __construct(protected Collection $frames)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function width(): int
|
||||
{
|
||||
return imagesx($this->frames->first()->getCore());
|
||||
@@ -30,9 +23,4 @@ class Image extends AbstractImage implements ImageInterface, IteratorAggregate
|
||||
{
|
||||
return imagesy($this->frames->first()->getCore());
|
||||
}
|
||||
|
||||
public function greyscale(): ImageInterface
|
||||
{
|
||||
return $this->modify(new Modifiers\GreyscaleModifier());
|
||||
}
|
||||
}
|
||||
|
@@ -13,11 +13,6 @@ use IteratorAggregate;
|
||||
|
||||
class Image extends AbstractImage implements ImageInterface, IteratorAggregate
|
||||
{
|
||||
public function __construct(protected Collection $frames)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function width(): int
|
||||
{
|
||||
return $this->frames->first()->getCore()->getImageWidth();
|
||||
@@ -27,9 +22,4 @@ class Image extends AbstractImage implements ImageInterface, IteratorAggregate
|
||||
{
|
||||
return $this->frames->first()->getCore()->getImageHeight();
|
||||
}
|
||||
|
||||
public function greyscale(): ImageInterface
|
||||
{
|
||||
return $this->modify(new Modifiers\GreyscaleModifier());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user