1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-31 01:29:51 +02:00

Refactoring

This commit is contained in:
Oliver Vogel
2021-10-22 16:15:49 +02:00
parent f7d6e26e4c
commit 99038d3a75
4 changed files with 21 additions and 25 deletions

View File

@@ -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')
);
}
}

View File

@@ -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) {

View File

@@ -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());
}
}

View File

@@ -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());
}
}