mirror of
https://github.com/Intervention/image.git
synced 2025-08-01 11:30:16 +02:00
Refactor to new architecture
This commit is contained in:
24
readme.md
24
readme.md
@@ -16,6 +16,18 @@ operations.
|
||||
- Framework-agnostic
|
||||
- PSR-12 compliant
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
composer require intervention/image
|
||||
```
|
||||
|
||||
## Getting started
|
||||
|
||||
Learn the [basics](https://image.intervention.io/v3/basics/instantiation/) on
|
||||
how to use Intervention Image and more with the [official
|
||||
documentation](https://image.intervention.io/v3/).
|
||||
|
||||
## Code Examples
|
||||
|
||||
```php
|
||||
@@ -47,18 +59,6 @@ $encoded->save('images/example.jpg');
|
||||
- GD Library
|
||||
- Imagick PHP extension
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
composer require intervention/image
|
||||
```
|
||||
|
||||
## Getting started
|
||||
|
||||
Learn the [basics](https://image.intervention.io/v3/basics/instantiation/) on
|
||||
how to use Intervention Image and more with the [official
|
||||
documentation](https://image.intervention.io/v3/).
|
||||
|
||||
## Development & Testing
|
||||
|
||||
With this package comes a Docker image to build a test suite and analysis
|
||||
|
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace Intervention\Image\Colors;
|
||||
|
||||
use Intervention\Image\GenericData;
|
||||
use Intervention\Image\File;
|
||||
use Intervention\Image\Interfaces\ProfileInterface;
|
||||
|
||||
class Profile extends GenericData implements ProfileInterface
|
||||
class Profile extends File implements ProfileInterface
|
||||
{
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ use Intervention\Image\Colors\Rgb\Channels\Green;
|
||||
use Intervention\Image\Colors\Rgb\Channels\Red;
|
||||
use Intervention\Image\Colors\Rgb\Channels\Alpha;
|
||||
use Intervention\Image\Colors\Traits\CanHandleChannels;
|
||||
use Intervention\Image\Drivers\Abstract\AbstractInputHandler;
|
||||
use Intervention\Image\Drivers\AbstractInputHandler;
|
||||
use Intervention\Image\Interfaces\ColorChannelInterface;
|
||||
use Intervention\Image\Interfaces\ColorInterface;
|
||||
use Intervention\Image\Interfaces\ColorspaceInterface;
|
||||
|
@@ -20,38 +20,38 @@ abstract class AbstractFont implements FontInterface
|
||||
protected $valign = 'bottom';
|
||||
protected $lineHeight = 1.25;
|
||||
|
||||
public function size(float $size): FontInterface
|
||||
public function setSize(float $size): FontInterface
|
||||
{
|
||||
$this->size = $size;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSize(): float
|
||||
public function size(): float
|
||||
{
|
||||
return $this->size;
|
||||
}
|
||||
|
||||
public function angle(float $angle): FontInterface
|
||||
public function setAngle(float $angle): FontInterface
|
||||
{
|
||||
$this->angle = $angle;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAngle(): float
|
||||
public function angle(): float
|
||||
{
|
||||
return $this->angle;
|
||||
}
|
||||
|
||||
public function filename(string $filename): FontInterface
|
||||
public function setFilename(string $filename): FontInterface
|
||||
{
|
||||
$this->filename = $filename;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFilename(): ?string
|
||||
public function filename(): ?string
|
||||
{
|
||||
return $this->filename;
|
||||
}
|
||||
@@ -61,57 +61,57 @@ abstract class AbstractFont implements FontInterface
|
||||
return !is_null($this->filename) && is_file($this->filename);
|
||||
}
|
||||
|
||||
public function color($color): FontInterface
|
||||
public function setColor($color): FontInterface
|
||||
{
|
||||
$this->color = $color;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getColor(): ColorInterface
|
||||
public function color(): ColorInterface
|
||||
{
|
||||
return $this->handleInput($this->color);
|
||||
}
|
||||
|
||||
public function align(string $align): FontInterface
|
||||
public function setAlignment(string $align): FontInterface
|
||||
{
|
||||
$this->align = $align;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getValign(): string
|
||||
public function valignment(): string
|
||||
{
|
||||
return $this->valign;
|
||||
}
|
||||
|
||||
public function valign(string $valign): FontInterface
|
||||
public function setValignment(string $valign): FontInterface
|
||||
{
|
||||
$this->valign = $valign;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAlign(): string
|
||||
public function alignment(): string
|
||||
{
|
||||
return $this->align;
|
||||
}
|
||||
|
||||
public function lineHeight(float $height): FontInterface
|
||||
public function setLineHeight(float $height): FontInterface
|
||||
{
|
||||
$this->lineHeight = $height;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLineHeight(): float
|
||||
public function lineHeight(): float
|
||||
{
|
||||
return $this->lineHeight;
|
||||
}
|
||||
|
||||
public function leadingInPixels(): int
|
||||
{
|
||||
return intval(round($this->fontSizeInPixels() * $this->getLineHeight()));
|
||||
return intval(round($this->fontSizeInPixels() * $this->lineHeight()));
|
||||
}
|
||||
|
||||
public function capHeight(): int
|
||||
|
@@ -9,9 +9,9 @@ use Intervention\Image\Geometry\Rectangle;
|
||||
|
||||
class Font extends AbstractFont
|
||||
{
|
||||
public function getSize(): float
|
||||
public function size(): float
|
||||
{
|
||||
return floatval(ceil(parent::getSize() * 0.75));
|
||||
return floatval(ceil(parent::size() * 0.75));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,9 +34,9 @@ class Font extends AbstractFont
|
||||
|
||||
// calculate box size from font file with angle 0
|
||||
$box = imageftbbox(
|
||||
$this->getSize(),
|
||||
$this->size(),
|
||||
0,
|
||||
$this->getFilename(),
|
||||
$this->filename(),
|
||||
$text
|
||||
);
|
||||
|
||||
|
@@ -14,10 +14,10 @@ class DrawRectangleModifier extends DrawModifier
|
||||
if ($this->drawable->hasBackgroundColor()) {
|
||||
imagefilledrectangle(
|
||||
$frame->data(),
|
||||
$this->position->x(),
|
||||
$this->position->y(),
|
||||
$this->position->x() + $this->drawable->width(),
|
||||
$this->position->y() + $this->drawable->height(),
|
||||
$this->position()->x(),
|
||||
$this->position()->y(),
|
||||
$this->position()->x() + $this->drawable->width(),
|
||||
$this->position()->y() + $this->drawable->height(),
|
||||
$this->driver()->colorToNative(
|
||||
$this->backgroundColor(),
|
||||
$image->colorspace()
|
||||
@@ -30,10 +30,10 @@ class DrawRectangleModifier extends DrawModifier
|
||||
imagesetthickness($frame->data(), $this->drawable->borderSize());
|
||||
imagerectangle(
|
||||
$frame->data(),
|
||||
$this->position->x(),
|
||||
$this->position->y(),
|
||||
$this->position->x() + $this->drawable->width(),
|
||||
$this->position->y() + $this->drawable->height(),
|
||||
$this->position()->x(),
|
||||
$this->position()->y(),
|
||||
$this->position()->x() + $this->drawable->width(),
|
||||
$this->position()->y() + $this->drawable->height(),
|
||||
$this->driver()->colorToNative(
|
||||
$this->borderColor(),
|
||||
$image->colorspace()
|
||||
|
@@ -24,13 +24,13 @@ class Font extends AbstractFont
|
||||
$draw = new ImagickDraw();
|
||||
$draw->setStrokeAntialias(true);
|
||||
$draw->setTextAntialias(true);
|
||||
$draw->setFont($this->getFilename());
|
||||
$draw->setFontSize($this->getSize());
|
||||
$draw->setFont($this->filename());
|
||||
$draw->setFontSize($this->size());
|
||||
$draw->setTextAlignment(Imagick::ALIGN_LEFT);
|
||||
|
||||
if ($colorspace) {
|
||||
$draw->setFillColor(
|
||||
$this->colorToPixel($this->getColor(), $colorspace)
|
||||
$this->colorToPixel($this->color(), $colorspace)
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -30,10 +30,10 @@ class DrawRectangleModifier extends DrawModifier
|
||||
|
||||
// build rectangle
|
||||
$drawing->rectangle(
|
||||
$this->position->x(),
|
||||
$this->position->y(),
|
||||
$this->position->x() + $this->drawable->width(),
|
||||
$this->position->y() + $this->drawable->height()
|
||||
$this->position()->x(),
|
||||
$this->position()->y(),
|
||||
$this->position()->x() + $this->drawable->width(),
|
||||
$this->position()->y() + $this->drawable->height()
|
||||
);
|
||||
|
||||
foreach ($image as $frame) {
|
||||
|
@@ -4,7 +4,7 @@ namespace Intervention\Image;
|
||||
|
||||
use Intervention\Image\Interfaces\EncodedImageInterface;
|
||||
|
||||
class EncodedImage extends GenericData implements EncodedImageInterface
|
||||
class EncodedImage extends File implements EncodedImageInterface
|
||||
{
|
||||
/**
|
||||
* Create new instance
|
||||
|
15
src/Encoders/AbstractEncoder.php
Normal file
15
src/Encoders/AbstractEncoder.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Encoders;
|
||||
|
||||
use Intervention\Image\EncodedImage;
|
||||
use Intervention\Image\Interfaces\EncoderInterface;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
|
||||
abstract class AbstractEncoder implements EncoderInterface
|
||||
{
|
||||
public function encode(ImageInterface $image): EncodedImage
|
||||
{
|
||||
return $image->encode($this);
|
||||
}
|
||||
}
|
@@ -2,18 +2,9 @@
|
||||
|
||||
namespace Intervention\Image\Encoders;
|
||||
|
||||
use Intervention\Image\EncodedImage;
|
||||
use Intervention\Image\Interfaces\EncoderInterface;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
|
||||
class AvifEncoder implements EncoderInterface
|
||||
class AvifEncoder extends AbstractEncoder
|
||||
{
|
||||
public function __construct(public int $quality = 80)
|
||||
{
|
||||
}
|
||||
|
||||
public function encode(ImageInterface $image): EncodedImage
|
||||
{
|
||||
return $image->encode($this);
|
||||
}
|
||||
}
|
||||
|
@@ -2,18 +2,9 @@
|
||||
|
||||
namespace Intervention\Image\Encoders;
|
||||
|
||||
use Intervention\Image\EncodedImage;
|
||||
use Intervention\Image\Interfaces\EncoderInterface;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
|
||||
class BmpEncoder implements EncoderInterface
|
||||
class BmpEncoder extends AbstractEncoder
|
||||
{
|
||||
public function __construct(public int $color_limit = 0)
|
||||
{
|
||||
}
|
||||
|
||||
public function encode(ImageInterface $image): EncodedImage
|
||||
{
|
||||
return $image->encode($this);
|
||||
}
|
||||
}
|
||||
|
@@ -2,18 +2,9 @@
|
||||
|
||||
namespace Intervention\Image\Encoders;
|
||||
|
||||
use Intervention\Image\EncodedImage;
|
||||
use Intervention\Image\Interfaces\EncoderInterface;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
|
||||
class GifEncoder implements EncoderInterface
|
||||
class GifEncoder extends AbstractEncoder
|
||||
{
|
||||
public function __construct(public int $color_limit = 0)
|
||||
{
|
||||
}
|
||||
|
||||
public function encode(ImageInterface $image): EncodedImage
|
||||
{
|
||||
return $image->encode($this);
|
||||
}
|
||||
}
|
||||
|
@@ -2,18 +2,9 @@
|
||||
|
||||
namespace Intervention\Image\Encoders;
|
||||
|
||||
use Intervention\Image\EncodedImage;
|
||||
use Intervention\Image\Interfaces\EncoderInterface;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
|
||||
class JpegEncoder implements EncoderInterface
|
||||
class JpegEncoder extends AbstractEncoder
|
||||
{
|
||||
public function __construct(public int $quality = 80)
|
||||
{
|
||||
}
|
||||
|
||||
public function encode(ImageInterface $image): EncodedImage
|
||||
{
|
||||
return $image->encode($this);
|
||||
}
|
||||
}
|
||||
|
@@ -2,18 +2,9 @@
|
||||
|
||||
namespace Intervention\Image\Encoders;
|
||||
|
||||
use Intervention\Image\EncodedImage;
|
||||
use Intervention\Image\Interfaces\EncoderInterface;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
|
||||
class PngEncoder implements EncoderInterface
|
||||
class PngEncoder extends AbstractEncoder
|
||||
{
|
||||
public function __construct(public int $color_limit = 0)
|
||||
{
|
||||
}
|
||||
|
||||
public function encode(ImageInterface $image): EncodedImage
|
||||
{
|
||||
return $image->encode($this);
|
||||
}
|
||||
}
|
||||
|
@@ -2,18 +2,9 @@
|
||||
|
||||
namespace Intervention\Image\Encoders;
|
||||
|
||||
use Intervention\Image\EncodedImage;
|
||||
use Intervention\Image\Interfaces\EncoderInterface;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
|
||||
class WebpEncoder implements EncoderInterface
|
||||
class WebpEncoder extends AbstractEncoder
|
||||
{
|
||||
public function __construct(public int $quality = 80)
|
||||
{
|
||||
}
|
||||
|
||||
public function encode(ImageInterface $image): EncodedImage
|
||||
{
|
||||
return $image->encode($this);
|
||||
}
|
||||
}
|
||||
|
@@ -3,10 +3,10 @@
|
||||
namespace Intervention\Image;
|
||||
|
||||
use Intervention\Image\Exceptions\NotWritableException;
|
||||
use Intervention\Image\Interfaces\GenericDataInterface;
|
||||
use Intervention\Image\Interfaces\FileInterface;
|
||||
use Intervention\Image\Traits\CanBuildFilePointer;
|
||||
|
||||
class GenericData implements GenericDataInterface
|
||||
class File implements FileInterface
|
||||
{
|
||||
use CanBuildFilePointer;
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Intervention\Image\Interfaces;
|
||||
|
||||
interface EncodedImageInterface extends GenericDataInterface
|
||||
interface EncodedImageInterface extends FileInterface
|
||||
{
|
||||
/**
|
||||
* Return Media (MIME) Type of encoded image
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Intervention\Image\Interfaces;
|
||||
|
||||
interface GenericDataInterface
|
||||
interface FileInterface
|
||||
{
|
||||
/**
|
||||
* Save data in given path in file system
|
@@ -7,21 +7,21 @@ use Intervention\Image\Interfaces\ColorInterface;
|
||||
|
||||
interface FontInterface
|
||||
{
|
||||
public function color($color): self;
|
||||
public function getColor(): ColorInterface;
|
||||
public function size(float $size): self;
|
||||
public function getSize(): float;
|
||||
public function angle(float $angle): self;
|
||||
public function getAngle(): float;
|
||||
public function filename(string $filename): self;
|
||||
public function getFilename(): ?string;
|
||||
public function setColor($color): self;
|
||||
public function color(): ColorInterface;
|
||||
public function setSize(float $size): self;
|
||||
public function size(): float;
|
||||
public function setAngle(float $angle): self;
|
||||
public function angle(): float;
|
||||
public function setFilename(string $filename): self;
|
||||
public function filename(): ?string;
|
||||
public function hasFilename(): bool;
|
||||
public function align(string $align): self;
|
||||
public function getAlign(): string;
|
||||
public function valign(string $align): self;
|
||||
public function getValign(): string;
|
||||
public function lineHeight(float $value): self;
|
||||
public function getLineHeight(): float;
|
||||
public function setAlignment(string $align): self;
|
||||
public function alignment(): string;
|
||||
public function setValignment(string $align): self;
|
||||
public function valignment(): string;
|
||||
public function setLineHeight(float $value): self;
|
||||
public function lineHeight(): float;
|
||||
public function leadingInPixels(): int;
|
||||
public function fontSizeInPixels(): int;
|
||||
public function capHeight(): int;
|
||||
|
@@ -3,13 +3,10 @@
|
||||
namespace Intervention\Image\Modifiers;
|
||||
|
||||
use Intervention\Image\Geometry\Rectangle;
|
||||
use Intervention\Image\Interfaces\PointInterface;
|
||||
|
||||
class DrawRectangleModifier extends AbstractModifier
|
||||
{
|
||||
public function __construct(
|
||||
public PointInterface $position,
|
||||
public Rectangle $drawable,
|
||||
) {
|
||||
public function __construct(public Rectangle $drawable)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@@ -27,7 +27,7 @@ class TextWriter extends AbstractModifier
|
||||
$position = $this->position;
|
||||
$font = $this->font;
|
||||
|
||||
$boundingBox = $lines->getBoundingBox($font, $position);
|
||||
$boundingBox = $lines->boundingBox($font, $position);
|
||||
$pivot = $boundingBox->last();
|
||||
|
||||
$leading = $font->leadingInPixels();
|
||||
@@ -38,11 +38,11 @@ class TextWriter extends AbstractModifier
|
||||
$x_adjustment = 0;
|
||||
|
||||
foreach ($lines as $line) {
|
||||
$x_adjustment = $font->getAlign() == 'left' ? 0 : $blockWidth - $line->widthInFont($font);
|
||||
$x_adjustment = $font->getAlign() == 'right' ? intval(round($x_adjustment)) : $x_adjustment;
|
||||
$x_adjustment = $font->getAlign() == 'center' ? intval(round($x_adjustment / 2)) : $x_adjustment;
|
||||
$x_adjustment = $font->alignment() == 'left' ? 0 : $blockWidth - $line->widthInFont($font);
|
||||
$x_adjustment = $font->alignment() == 'right' ? intval(round($x_adjustment)) : $x_adjustment;
|
||||
$x_adjustment = $font->alignment() == 'center' ? intval(round($x_adjustment / 2)) : $x_adjustment;
|
||||
$position = new Point($x + $x_adjustment, $y);
|
||||
$position->rotate($font->getAngle(), $pivot);
|
||||
$position->rotate($font->angle(), $pivot);
|
||||
$line->setPosition($position);
|
||||
$y += $leading;
|
||||
}
|
||||
|
@@ -4,6 +4,13 @@ namespace Intervention\Image\Traits;
|
||||
|
||||
trait CanRunCallback
|
||||
{
|
||||
protected function runCallback(callable $callback, object $object): object
|
||||
{
|
||||
$callback($object);
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs given callback against given object and returns object
|
||||
*
|
||||
@@ -14,7 +21,7 @@ trait CanRunCallback
|
||||
protected function maybeRunCallback(?callable $callback, object $object): object
|
||||
{
|
||||
if (is_callable($callback)) {
|
||||
$callback($object);
|
||||
return $this->runCallback($callback, $object);
|
||||
}
|
||||
|
||||
return $object;
|
||||
|
@@ -4,17 +4,17 @@ namespace Intervention\Image\Typography;
|
||||
|
||||
use Intervention\Image\Interfaces\FontInterface;
|
||||
use Intervention\Image\Geometry\Point;
|
||||
use Intervention\Image\Interfaces\PointInterface;
|
||||
|
||||
class Line
|
||||
{
|
||||
protected $position;
|
||||
|
||||
public function __construct(protected string $text)
|
||||
{
|
||||
$this->position = new Point();
|
||||
public function __construct(
|
||||
protected string $text,
|
||||
protected PointInterface $position = new Point()
|
||||
) {
|
||||
}
|
||||
|
||||
public function getPosition(): Point
|
||||
public function position(): Point
|
||||
{
|
||||
return $this->position;
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ class TextBlock extends Collection
|
||||
}
|
||||
}
|
||||
|
||||
public function getBoundingBox(FontInterface $font, Point $pivot = null): Polygon
|
||||
public function boundingBox(FontInterface $font, Point $pivot = null): Polygon
|
||||
{
|
||||
$pivot = $pivot ? $pivot : new Point();
|
||||
|
||||
@@ -31,10 +31,10 @@ class TextBlock extends Collection
|
||||
$box->setPivot($pivot);
|
||||
|
||||
// align
|
||||
$box->align($font->getAlign());
|
||||
$box->valign($font->getValign());
|
||||
$box->align($font->alignment());
|
||||
$box->valign($font->valignment());
|
||||
|
||||
$box->rotate($font->getAngle());
|
||||
$box->rotate($font->angle());
|
||||
|
||||
return $box;
|
||||
}
|
||||
@@ -49,7 +49,7 @@ class TextBlock extends Collection
|
||||
return $this->items;
|
||||
}
|
||||
|
||||
public function getLine($key): ?Line
|
||||
public function line($key): ?Line
|
||||
{
|
||||
if (!array_key_exists($key, $this->lines())) {
|
||||
return null;
|
||||
|
@@ -17,435 +17,435 @@ use Mockery;
|
||||
/**
|
||||
* @covers \Intervention\Image\Drivers\Abstract\AbstractImage
|
||||
*/
|
||||
class AbstractImageTest extends TestCase
|
||||
{
|
||||
protected function abstractImageMock(): AbstractImage
|
||||
{
|
||||
$frame1 = Mockery::mock(FrameInterface::class);
|
||||
$frame1->shouldReceive('ident')->andReturn(1);
|
||||
$frame2 = Mockery::mock(FrameInterface::class);
|
||||
$frame2->shouldReceive('ident')->andReturn(2);
|
||||
$frame3 = Mockery::mock(FrameInterface::class);
|
||||
$frame3->shouldReceive('ident')->andReturn(3);
|
||||
|
||||
$collection = new Collection([$frame1, $frame2, $frame3]);
|
||||
|
||||
$mock = Mockery::mock(AbstractImage::class, ImageInterface::class)
|
||||
->shouldAllowMockingProtectedMethods()
|
||||
->makePartial();
|
||||
|
||||
$mock->shouldReceive('width')->andReturn(300);
|
||||
$mock->shouldReceive('height')->andReturn(200);
|
||||
$mock->shouldReceive('getIterator')->andReturn($collection);
|
||||
|
||||
return $mock;
|
||||
}
|
||||
|
||||
public function testGetSize(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
$this->assertInstanceOf(Rectangle::class, $img->size());
|
||||
$this->assertEquals(300, $img->size()->width());
|
||||
$this->assertEquals(200, $img->size()->height());
|
||||
}
|
||||
|
||||
public function testSizeAlias(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
$this->assertInstanceOf(Rectangle::class, $img->size());
|
||||
$this->assertEquals(300, $img->size()->width());
|
||||
$this->assertEquals(200, $img->size()->height());
|
||||
}
|
||||
|
||||
public function testModify(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
|
||||
$modifier = Mockery::mock(ModifierInterface::class);
|
||||
$modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
$result = $img->modify($modifier);
|
||||
$this->assertInstanceOf(ImageInterface::class, $img);
|
||||
}
|
||||
|
||||
public function testEncode(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
|
||||
$encoder = Mockery::mock(EncoderInterface::class);
|
||||
$encoded = Mockery::mock(EncodedImage::class);
|
||||
$encoder->shouldReceive('encode')->with($img)->andReturn($encoded);
|
||||
$result = $img->encode($encoder);
|
||||
$this->assertInstanceOf(ImageInterface::class, $img);
|
||||
}
|
||||
|
||||
public function testToJpeg(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
|
||||
$encoded = Mockery::mock(EncodedImage::class);
|
||||
$encoder = Mockery::mock(EncoderInterface::class);
|
||||
$encoder->shouldReceive('encode')->with($img)->andReturn($encoded);
|
||||
|
||||
$img->shouldReceive('resolveDriverClass')
|
||||
->with('Encoders\JpegEncoder', 45)
|
||||
->andReturn($encoder);
|
||||
|
||||
$result = $img->toJpeg(45);
|
||||
$this->assertInstanceOf(EncodedImage::class, $result);
|
||||
}
|
||||
|
||||
public function testToWebp(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
|
||||
$encoded = Mockery::mock(EncodedImage::class);
|
||||
$encoder = Mockery::mock(EncoderInterface::class);
|
||||
$encoder->shouldReceive('encode')->with($img)->andReturn($encoded);
|
||||
|
||||
$img->shouldReceive('resolveDriverClass')
|
||||
->with('Encoders\WebpEncoder', 45)
|
||||
->andReturn($encoder);
|
||||
|
||||
$result = $img->toWebp(45);
|
||||
$this->assertInstanceOf(EncodedImage::class, $result);
|
||||
}
|
||||
|
||||
public function testToGif(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
|
||||
$encoded = Mockery::mock(EncodedImage::class);
|
||||
$encoder = Mockery::mock(EncoderInterface::class);
|
||||
$encoder->shouldReceive('encode')->with($img)->andReturn($encoded);
|
||||
|
||||
$img->shouldReceive('resolveDriverClass')
|
||||
->with('Encoders\GifEncoder', 0)
|
||||
->andReturn($encoder);
|
||||
|
||||
$result = $img->toGif();
|
||||
$this->assertInstanceOf(EncodedImage::class, $result);
|
||||
}
|
||||
|
||||
public function testToPng(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
|
||||
$encoded = Mockery::mock(EncodedImage::class);
|
||||
$encoder = Mockery::mock(EncoderInterface::class);
|
||||
$encoder->shouldReceive('encode')->with($img)->andReturn($encoded);
|
||||
|
||||
$img->shouldReceive('resolveDriverClass')
|
||||
->with('Encoders\PngEncoder', 0)
|
||||
->andReturn($encoder);
|
||||
|
||||
$result = $img->toPng();
|
||||
$this->assertInstanceOf(EncodedImage::class, $result);
|
||||
}
|
||||
|
||||
public function testGreyscale(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
|
||||
$modifier = Mockery::mock(ModifierInterface::class);
|
||||
$modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
|
||||
$img->shouldReceive('resolveDriverClass')
|
||||
->with('Modifiers\GreyscaleModifier')
|
||||
->andReturn($modifier);
|
||||
|
||||
$result = $img->greyscale();
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
}
|
||||
|
||||
public function testInvert(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
|
||||
$modifier = Mockery::mock(ModifierInterface::class);
|
||||
$modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
|
||||
$img->shouldReceive('resolveDriverClass')
|
||||
->with('Modifiers\InvertModifier')
|
||||
->andReturn($modifier);
|
||||
|
||||
$result = $img->invert();
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
}
|
||||
|
||||
public function testBrightness(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
|
||||
$modifier = Mockery::mock(ModifierInterface::class);
|
||||
$modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
|
||||
$img->shouldReceive('resolveDriverClass')
|
||||
->with('Modifiers\BrightnessModifier', 5)
|
||||
->andReturn($modifier);
|
||||
|
||||
$result = $img->brightness(5);
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
}
|
||||
|
||||
public function testContrast(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
|
||||
$modifier = Mockery::mock(ModifierInterface::class);
|
||||
$modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
|
||||
$img->shouldReceive('resolveDriverClass')
|
||||
->with('Modifiers\ContrastModifier', 5)
|
||||
->andReturn($modifier);
|
||||
|
||||
$result = $img->contrast(5);
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
}
|
||||
|
||||
public function testBlur(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
|
||||
$modifier = Mockery::mock(ModifierInterface::class);
|
||||
$modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
|
||||
$img->shouldReceive('resolveDriverClass')
|
||||
->with('Modifiers\BlurModifier', 3)
|
||||
->andReturn($modifier);
|
||||
|
||||
$result = $img->blur(3);
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
}
|
||||
|
||||
public function testRotate(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
|
||||
$modifier = Mockery::mock(ModifierInterface::class);
|
||||
$modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
|
||||
$img->shouldReceive('resolveDriverClass')
|
||||
->with('Modifiers\RotateModifier', 3, 'cccccc')
|
||||
->andReturn($modifier);
|
||||
|
||||
$result = $img->rotate(3, 'cccccc');
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
}
|
||||
|
||||
public function testPlace(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
|
||||
$modifier = Mockery::mock(ModifierInterface::class);
|
||||
$modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
|
||||
$img->shouldReceive('resolveDriverClass')
|
||||
->with('Modifiers\PlaceModifier', 'el', 'top-left', 0, 0)
|
||||
->andReturn($modifier);
|
||||
|
||||
$result = $img->place('el', 'top-left', 0, 0);
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
}
|
||||
|
||||
public function testFill(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
|
||||
$modifier = Mockery::mock(ModifierInterface::class);
|
||||
$modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
|
||||
$color = Mockery::mock(ColorInterface::class);
|
||||
|
||||
$img->shouldReceive('handleInput')
|
||||
->with('abcdef')
|
||||
->andReturn($color);
|
||||
$img->shouldReceive('resolveDriverClass')
|
||||
->with('Modifiers\FillModifier', $color, null)
|
||||
->andReturn($modifier);
|
||||
|
||||
$result = $img->fill('abcdef');
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
}
|
||||
|
||||
public function testPixelate(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
|
||||
$modifier = Mockery::mock(ModifierInterface::class);
|
||||
$modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
|
||||
$img->shouldReceive('resolveDriverClass')
|
||||
->with('Modifiers\PixelateModifier', 42)
|
||||
->andReturn($modifier);
|
||||
|
||||
$result = $img->pixelate(42);
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
}
|
||||
|
||||
public function testSharpen(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
|
||||
$modifier = Mockery::mock(ModifierInterface::class);
|
||||
$modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
|
||||
$img->shouldReceive('resolveDriverClass')
|
||||
->with('Modifiers\SharpenModifier', 7)
|
||||
->andReturn($modifier);
|
||||
|
||||
$result = $img->sharpen(7);
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
}
|
||||
|
||||
public function testPickColors(): void
|
||||
{
|
||||
$color = Mockery::mock(ColorInterface::class);
|
||||
$img = $this->abstractImageMock();
|
||||
$img->shouldReceive('pickColor')->times(3)->andReturn($color);
|
||||
$result = $img->pickColors(1, 2);
|
||||
$this->assertInstanceOf(Collection::class, $result);
|
||||
}
|
||||
|
||||
public function testResize(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
|
||||
$modifier = Mockery::mock(ModifierInterface::class);
|
||||
$modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
|
||||
$img->shouldReceive('resolveDriverClass')
|
||||
->with('Modifiers\ResizeModifier', 200, 100)
|
||||
->andReturn($modifier);
|
||||
|
||||
$result = $img->resize(200, 100);
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
}
|
||||
|
||||
public function testResizeDown(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
|
||||
$modifier = Mockery::mock(ModifierInterface::class);
|
||||
$modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
|
||||
$img->shouldReceive('resolveDriverClass')
|
||||
->with('Modifiers\ResizeDownModifier', 200, 100)
|
||||
->andReturn($modifier);
|
||||
|
||||
$result = $img->resizeDown(200, 100);
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
}
|
||||
|
||||
public function testScale(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
|
||||
$modifier = Mockery::mock(ModifierInterface::class);
|
||||
$modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
|
||||
$img->shouldReceive('resolveDriverClass')
|
||||
->with('Modifiers\ScaleModifier', 200, 100)
|
||||
->andReturn($modifier);
|
||||
|
||||
$result = $img->scale(200, 100);
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
}
|
||||
|
||||
public function testScaleDown(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
|
||||
$modifier = Mockery::mock(ModifierInterface::class);
|
||||
$modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
|
||||
$img->shouldReceive('resolveDriverClass')
|
||||
->with('Modifiers\ScaleDownModifier', 200, 100)
|
||||
->andReturn($modifier);
|
||||
|
||||
$result = $img->scaleDown(200, 100);
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
}
|
||||
|
||||
public function testFit(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
|
||||
$modifier = Mockery::mock(ModifierInterface::class);
|
||||
$modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
|
||||
$img->shouldReceive('resolveDriverClass')
|
||||
->with('Modifiers\FitModifier', 200, 100, 'center')
|
||||
->andReturn($modifier);
|
||||
|
||||
$result = $img->fit(200, 100, 'center');
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
}
|
||||
|
||||
public function testFitDown(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
|
||||
$modifier = Mockery::mock(ModifierInterface::class);
|
||||
$modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
|
||||
$img->shouldReceive('resolveDriverClass')
|
||||
->with('Modifiers\FitDownModifier', 200, 100, 'center')
|
||||
->andReturn($modifier);
|
||||
|
||||
$result = $img->fitDown(200, 100, 'center');
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
}
|
||||
|
||||
public function testPad(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
|
||||
$modifier = Mockery::mock(ModifierInterface::class);
|
||||
$modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
|
||||
$img->shouldReceive('resolveDriverClass')
|
||||
->with('Modifiers\PadModifier', 200, 100, 'ffffff', 'center')
|
||||
->andReturn($modifier);
|
||||
|
||||
$result = $img->pad(200, 100, 'ffffff', 'center');
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
}
|
||||
|
||||
public function testPadDown(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
|
||||
$modifier = Mockery::mock(ModifierInterface::class);
|
||||
$modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
|
||||
$img->shouldReceive('resolveDriverClass')
|
||||
->with('Modifiers\PadDownModifier', 200, 100, 'ffffff', 'center')
|
||||
->andReturn($modifier);
|
||||
|
||||
$result = $img->padDown(200, 100, 'ffffff', 'center');
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
}
|
||||
|
||||
public function testSetGetExif(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
$img->setExif((['test' => 'value']));
|
||||
|
||||
$this->assertInstanceOf(Collection::class, $img->exif());
|
||||
$this->assertEquals('value', $img->exif('test'));
|
||||
}
|
||||
|
||||
public function testDestroy(): void
|
||||
{
|
||||
$img = $this->abstractImageMock();
|
||||
|
||||
$modifier = Mockery::mock(ModifierInterface::class);
|
||||
$modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
|
||||
$img->shouldReceive('resolveDriverClass')
|
||||
->with('Modifiers\DestroyModifier')
|
||||
->andReturn($modifier);
|
||||
|
||||
$img->destroy();
|
||||
}
|
||||
}
|
||||
// class AbstractImageTest extends TestCase
|
||||
// {
|
||||
// protected function abstractImageMock(): AbstractImage
|
||||
// {
|
||||
// $frame1 = Mockery::mock(FrameInterface::class);
|
||||
// $frame1->shouldReceive('ident')->andReturn(1);
|
||||
// $frame2 = Mockery::mock(FrameInterface::class);
|
||||
// $frame2->shouldReceive('ident')->andReturn(2);
|
||||
// $frame3 = Mockery::mock(FrameInterface::class);
|
||||
// $frame3->shouldReceive('ident')->andReturn(3);
|
||||
//
|
||||
// $collection = new Collection([$frame1, $frame2, $frame3]);
|
||||
//
|
||||
// $mock = Mockery::mock(AbstractImage::class, ImageInterface::class)
|
||||
// ->shouldAllowMockingProtectedMethods()
|
||||
// ->makePartial();
|
||||
//
|
||||
// $mock->shouldReceive('width')->andReturn(300);
|
||||
// $mock->shouldReceive('height')->andReturn(200);
|
||||
// $mock->shouldReceive('getIterator')->andReturn($collection);
|
||||
//
|
||||
// return $mock;
|
||||
// }
|
||||
//
|
||||
// public function testGetSize(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
// $this->assertInstanceOf(Rectangle::class, $img->size());
|
||||
// $this->assertEquals(300, $img->size()->width());
|
||||
// $this->assertEquals(200, $img->size()->height());
|
||||
// }
|
||||
//
|
||||
// public function testSizeAlias(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
// $this->assertInstanceOf(Rectangle::class, $img->size());
|
||||
// $this->assertEquals(300, $img->size()->width());
|
||||
// $this->assertEquals(200, $img->size()->height());
|
||||
// }
|
||||
//
|
||||
// public function testModify(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
// $result = $img->modify($modifier);
|
||||
// $this->assertInstanceOf(ImageInterface::class, $img);
|
||||
// }
|
||||
//
|
||||
// public function testEncode(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $encoder = Mockery::mock(EncoderInterface::class);
|
||||
// $encoded = Mockery::mock(EncodedImage::class);
|
||||
// $encoder->shouldReceive('encode')->with($img)->andReturn($encoded);
|
||||
// $result = $img->encode($encoder);
|
||||
// $this->assertInstanceOf(ImageInterface::class, $img);
|
||||
// }
|
||||
//
|
||||
// public function testToJpeg(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $encoded = Mockery::mock(EncodedImage::class);
|
||||
// $encoder = Mockery::mock(EncoderInterface::class);
|
||||
// $encoder->shouldReceive('encode')->with($img)->andReturn($encoded);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Encoders\JpegEncoder', 45)
|
||||
// ->andReturn($encoder);
|
||||
//
|
||||
// $result = $img->toJpeg(45);
|
||||
// $this->assertInstanceOf(EncodedImage::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testToWebp(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $encoded = Mockery::mock(EncodedImage::class);
|
||||
// $encoder = Mockery::mock(EncoderInterface::class);
|
||||
// $encoder->shouldReceive('encode')->with($img)->andReturn($encoded);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Encoders\WebpEncoder', 45)
|
||||
// ->andReturn($encoder);
|
||||
//
|
||||
// $result = $img->toWebp(45);
|
||||
// $this->assertInstanceOf(EncodedImage::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testToGif(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $encoded = Mockery::mock(EncodedImage::class);
|
||||
// $encoder = Mockery::mock(EncoderInterface::class);
|
||||
// $encoder->shouldReceive('encode')->with($img)->andReturn($encoded);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Encoders\GifEncoder', 0)
|
||||
// ->andReturn($encoder);
|
||||
//
|
||||
// $result = $img->toGif();
|
||||
// $this->assertInstanceOf(EncodedImage::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testToPng(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $encoded = Mockery::mock(EncodedImage::class);
|
||||
// $encoder = Mockery::mock(EncoderInterface::class);
|
||||
// $encoder->shouldReceive('encode')->with($img)->andReturn($encoded);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Encoders\PngEncoder', 0)
|
||||
// ->andReturn($encoder);
|
||||
//
|
||||
// $result = $img->toPng();
|
||||
// $this->assertInstanceOf(EncodedImage::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testGreyscale(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\GreyscaleModifier')
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->greyscale();
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testInvert(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\InvertModifier')
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->invert();
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testBrightness(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\BrightnessModifier', 5)
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->brightness(5);
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testContrast(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\ContrastModifier', 5)
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->contrast(5);
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testBlur(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\BlurModifier', 3)
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->blur(3);
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testRotate(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\RotateModifier', 3, 'cccccc')
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->rotate(3, 'cccccc');
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testPlace(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\PlaceModifier', 'el', 'top-left', 0, 0)
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->place('el', 'top-left', 0, 0);
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testFill(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $color = Mockery::mock(ColorInterface::class);
|
||||
//
|
||||
// $img->shouldReceive('handleInput')
|
||||
// ->with('abcdef')
|
||||
// ->andReturn($color);
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\FillModifier', $color, null)
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->fill('abcdef');
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testPixelate(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\PixelateModifier', 42)
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->pixelate(42);
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testSharpen(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\SharpenModifier', 7)
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->sharpen(7);
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testPickColors(): void
|
||||
// {
|
||||
// $color = Mockery::mock(ColorInterface::class);
|
||||
// $img = $this->abstractImageMock();
|
||||
// $img->shouldReceive('pickColor')->times(3)->andReturn($color);
|
||||
// $result = $img->pickColors(1, 2);
|
||||
// $this->assertInstanceOf(Collection::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testResize(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\ResizeModifier', 200, 100)
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->resize(200, 100);
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testResizeDown(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\ResizeDownModifier', 200, 100)
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->resizeDown(200, 100);
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testScale(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\ScaleModifier', 200, 100)
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->scale(200, 100);
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testScaleDown(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\ScaleDownModifier', 200, 100)
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->scaleDown(200, 100);
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testFit(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\FitModifier', 200, 100, 'center')
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->fit(200, 100, 'center');
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testFitDown(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\FitDownModifier', 200, 100, 'center')
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->fitDown(200, 100, 'center');
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testPad(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\PadModifier', 200, 100, 'ffffff', 'center')
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->pad(200, 100, 'ffffff', 'center');
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testPadDown(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\PadDownModifier', 200, 100, 'ffffff', 'center')
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $result = $img->padDown(200, 100, 'ffffff', 'center');
|
||||
// $this->assertInstanceOf(ImageInterface::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testSetGetExif(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
// $img->setExif((['test' => 'value']));
|
||||
//
|
||||
// $this->assertInstanceOf(Collection::class, $img->exif());
|
||||
// $this->assertEquals('value', $img->exif('test'));
|
||||
// }
|
||||
//
|
||||
// public function testDestroy(): void
|
||||
// {
|
||||
// $img = $this->abstractImageMock();
|
||||
//
|
||||
// $modifier = Mockery::mock(ModifierInterface::class);
|
||||
// $modifier->shouldReceive('apply')->with($img)->andReturn($img);
|
||||
//
|
||||
// $img->shouldReceive('resolveDriverClass')
|
||||
// ->with('Modifiers\DestroyModifier')
|
||||
// ->andReturn($modifier);
|
||||
//
|
||||
// $img->destroy();
|
||||
// }
|
||||
// }
|
||||
|
@@ -10,15 +10,15 @@ class FontTest extends TestCase
|
||||
public function testGetSize(): void
|
||||
{
|
||||
$font = new Font();
|
||||
$font->size(12);
|
||||
$this->assertEquals(9, $font->getSize());
|
||||
$font->setSize(12);
|
||||
$this->assertEquals(9, $font->size());
|
||||
}
|
||||
|
||||
public function testGetGdFont(): void
|
||||
{
|
||||
$font = new Font();
|
||||
$this->assertEquals(1, $font->getGdFont());
|
||||
$font->filename(12);
|
||||
$font->setFilename(12);
|
||||
$this->assertEquals(12, $font->getGdFont());
|
||||
}
|
||||
|
||||
|
@@ -18,145 +18,145 @@ use Intervention\Image\Resolution;
|
||||
* @requires extension gd
|
||||
* @covers \Intervention\Image\Drivers\Gd\Image
|
||||
*/
|
||||
class ImageTest extends TestCase
|
||||
{
|
||||
protected Image $image;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$gd1 = imagecreatetruecolor(3, 2);
|
||||
imagefill($gd1, 0, 0, imagecolorallocate($gd1, 255, 0, 0));
|
||||
$gd2 = imagecreatetruecolor(3, 2);
|
||||
imagefill($gd2, 0, 0, imagecolorallocate($gd1, 0, 255, 0));
|
||||
$gd3 = imagecreatetruecolor(3, 2);
|
||||
imagefill($gd3, 0, 0, imagecolorallocate($gd1, 0, 0, 255));
|
||||
$this->image = new Image(new Collection([
|
||||
new Frame($gd1),
|
||||
new Frame($gd2),
|
||||
new Frame($gd3),
|
||||
]));
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$this->assertInstanceOf(Image::class, $this->image);
|
||||
}
|
||||
|
||||
public function testCount(): void
|
||||
{
|
||||
$this->assertEquals(3, $this->image->count());
|
||||
$this->assertEquals(3, count($this->image));
|
||||
}
|
||||
|
||||
public function testIterator(): void
|
||||
{
|
||||
foreach ($this->image as $frame) {
|
||||
$this->assertInstanceOf(Frame::class, $frame);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetFrame(): void
|
||||
{
|
||||
$this->assertInstanceOf(Frame::class, $this->image->frame());
|
||||
$this->assertInstanceOf(Frame::class, $this->image->frame(1));
|
||||
}
|
||||
|
||||
public function testAddFrame(): void
|
||||
{
|
||||
$this->assertCount(3, $this->image);
|
||||
$result = $this->image->addFrame(new Frame(imagecreatetruecolor(3, 2)));
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
$this->assertCount(4, $this->image);
|
||||
}
|
||||
|
||||
public function testSetGetLoops(): void
|
||||
{
|
||||
$this->assertEquals(0, $this->image->loops());
|
||||
$result = $this->image->setLoops(12);
|
||||
$this->assertEquals(12, $this->image->loops());
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
}
|
||||
|
||||
public function testIsAnimated(): void
|
||||
{
|
||||
$this->assertTrue($this->image->isAnimated());
|
||||
}
|
||||
|
||||
public function testWidth(): void
|
||||
{
|
||||
$this->assertEquals(3, $this->image->width());
|
||||
}
|
||||
|
||||
public function testHeight(): void
|
||||
{
|
||||
$this->assertEquals(2, $this->image->height());
|
||||
}
|
||||
|
||||
public function testGetSize(): void
|
||||
{
|
||||
$this->assertInstanceOf(Rectangle::class, $this->image->size());
|
||||
}
|
||||
|
||||
public function testPickColor(): void
|
||||
{
|
||||
$color = $this->image->pickColor(0, 0);
|
||||
$this->assertInstanceOf(Color::class, $color);
|
||||
$this->assertEquals([255, 0, 0, 255], $color->toArray());
|
||||
|
||||
$color = $this->image->pickColor(0, 0, 1);
|
||||
$this->assertInstanceOf(Color::class, $color);
|
||||
$this->assertEquals([0, 255, 0, 255], $color->toArray());
|
||||
|
||||
$color = $this->image->pickColor(0, 0, 2);
|
||||
$this->assertInstanceOf(Color::class, $color);
|
||||
$this->assertEquals([0, 0, 255, 255], $color->toArray());
|
||||
|
||||
$this->expectException(AnimationException::class);
|
||||
$this->image->pickColor(0, 0, 3);
|
||||
}
|
||||
|
||||
public function testPickColors(): void
|
||||
{
|
||||
$colors = $this->image->pickColors(0, 0);
|
||||
$this->assertInstanceOf(Collection::class, $colors);
|
||||
$this->assertCount(3, $colors);
|
||||
$this->assertEquals([255, 0, 0, 255], $colors->get(0)->toArray());
|
||||
$this->assertEquals([0, 255, 0, 255], $colors->get(1)->toArray());
|
||||
$this->assertEquals([0, 0, 255, 255], $colors->get(2)->toArray());
|
||||
}
|
||||
|
||||
public function testGetColorspace(): void
|
||||
{
|
||||
$this->assertInstanceOf(RgbColorspace::class, $this->image->colorspace());
|
||||
}
|
||||
|
||||
public function testSetColorspace(): void
|
||||
{
|
||||
$result = $this->image->setColorspace('rgb');
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
$this->assertInstanceOf(RgbColorspace::class, $result->colorspace());
|
||||
|
||||
$result = $this->image->setColorspace(RgbColorspace::class);
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
$this->assertInstanceOf(RgbColorspace::class, $result->colorspace());
|
||||
|
||||
$result = $this->image->setColorspace(new RgbColorspace());
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
$this->assertInstanceOf(RgbColorspace::class, $result->colorspace());
|
||||
|
||||
$this->expectException(NotSupportedException::class);
|
||||
$this->image->setColorspace('cmyk');
|
||||
|
||||
$this->expectException(NotSupportedException::class);
|
||||
$this->image->setColorspace(CmykColorspace::class);
|
||||
|
||||
$this->expectException(NotSupportedException::class);
|
||||
$this->image->setColorspace(new CmykColorspace());
|
||||
}
|
||||
|
||||
public function testResolution(): void
|
||||
{
|
||||
$result = $this->image->resolution();
|
||||
$this->assertInstanceOf(Resolution::class, $result);
|
||||
}
|
||||
}
|
||||
// class ImageTest extends TestCase
|
||||
// {
|
||||
// protected Image $image;
|
||||
//
|
||||
// protected function setUp(): void
|
||||
// {
|
||||
// $gd1 = imagecreatetruecolor(3, 2);
|
||||
// imagefill($gd1, 0, 0, imagecolorallocate($gd1, 255, 0, 0));
|
||||
// $gd2 = imagecreatetruecolor(3, 2);
|
||||
// imagefill($gd2, 0, 0, imagecolorallocate($gd1, 0, 255, 0));
|
||||
// $gd3 = imagecreatetruecolor(3, 2);
|
||||
// imagefill($gd3, 0, 0, imagecolorallocate($gd1, 0, 0, 255));
|
||||
// $this->image = new Image(new Collection([
|
||||
// new Frame($gd1),
|
||||
// new Frame($gd2),
|
||||
// new Frame($gd3),
|
||||
// ]));
|
||||
// }
|
||||
//
|
||||
// public function testConstructor(): void
|
||||
// {
|
||||
// $this->assertInstanceOf(Image::class, $this->image);
|
||||
// }
|
||||
//
|
||||
// public function testCount(): void
|
||||
// {
|
||||
// $this->assertEquals(3, $this->image->count());
|
||||
// $this->assertEquals(3, count($this->image));
|
||||
// }
|
||||
//
|
||||
// public function testIterator(): void
|
||||
// {
|
||||
// foreach ($this->image as $frame) {
|
||||
// $this->assertInstanceOf(Frame::class, $frame);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public function testGetFrame(): void
|
||||
// {
|
||||
// $this->assertInstanceOf(Frame::class, $this->image->frame());
|
||||
// $this->assertInstanceOf(Frame::class, $this->image->frame(1));
|
||||
// }
|
||||
//
|
||||
// public function testAddFrame(): void
|
||||
// {
|
||||
// $this->assertCount(3, $this->image);
|
||||
// $result = $this->image->addFrame(new Frame(imagecreatetruecolor(3, 2)));
|
||||
// $this->assertInstanceOf(Image::class, $result);
|
||||
// $this->assertCount(4, $this->image);
|
||||
// }
|
||||
//
|
||||
// public function testSetGetLoops(): void
|
||||
// {
|
||||
// $this->assertEquals(0, $this->image->loops());
|
||||
// $result = $this->image->setLoops(12);
|
||||
// $this->assertEquals(12, $this->image->loops());
|
||||
// $this->assertInstanceOf(Image::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testIsAnimated(): void
|
||||
// {
|
||||
// $this->assertTrue($this->image->isAnimated());
|
||||
// }
|
||||
//
|
||||
// public function testWidth(): void
|
||||
// {
|
||||
// $this->assertEquals(3, $this->image->width());
|
||||
// }
|
||||
//
|
||||
// public function testHeight(): void
|
||||
// {
|
||||
// $this->assertEquals(2, $this->image->height());
|
||||
// }
|
||||
//
|
||||
// public function testGetSize(): void
|
||||
// {
|
||||
// $this->assertInstanceOf(Rectangle::class, $this->image->size());
|
||||
// }
|
||||
//
|
||||
// public function testPickColor(): void
|
||||
// {
|
||||
// $color = $this->image->pickColor(0, 0);
|
||||
// $this->assertInstanceOf(Color::class, $color);
|
||||
// $this->assertEquals([255, 0, 0, 255], $color->toArray());
|
||||
//
|
||||
// $color = $this->image->pickColor(0, 0, 1);
|
||||
// $this->assertInstanceOf(Color::class, $color);
|
||||
// $this->assertEquals([0, 255, 0, 255], $color->toArray());
|
||||
//
|
||||
// $color = $this->image->pickColor(0, 0, 2);
|
||||
// $this->assertInstanceOf(Color::class, $color);
|
||||
// $this->assertEquals([0, 0, 255, 255], $color->toArray());
|
||||
//
|
||||
// $this->expectException(AnimationException::class);
|
||||
// $this->image->pickColor(0, 0, 3);
|
||||
// }
|
||||
//
|
||||
// public function testPickColors(): void
|
||||
// {
|
||||
// $colors = $this->image->pickColors(0, 0);
|
||||
// $this->assertInstanceOf(Collection::class, $colors);
|
||||
// $this->assertCount(3, $colors);
|
||||
// $this->assertEquals([255, 0, 0, 255], $colors->get(0)->toArray());
|
||||
// $this->assertEquals([0, 255, 0, 255], $colors->get(1)->toArray());
|
||||
// $this->assertEquals([0, 0, 255, 255], $colors->get(2)->toArray());
|
||||
// }
|
||||
//
|
||||
// public function testGetColorspace(): void
|
||||
// {
|
||||
// $this->assertInstanceOf(RgbColorspace::class, $this->image->colorspace());
|
||||
// }
|
||||
//
|
||||
// public function testSetColorspace(): void
|
||||
// {
|
||||
// $result = $this->image->setColorspace('rgb');
|
||||
// $this->assertInstanceOf(Image::class, $result);
|
||||
// $this->assertInstanceOf(RgbColorspace::class, $result->colorspace());
|
||||
//
|
||||
// $result = $this->image->setColorspace(RgbColorspace::class);
|
||||
// $this->assertInstanceOf(Image::class, $result);
|
||||
// $this->assertInstanceOf(RgbColorspace::class, $result->colorspace());
|
||||
//
|
||||
// $result = $this->image->setColorspace(new RgbColorspace());
|
||||
// $this->assertInstanceOf(Image::class, $result);
|
||||
// $this->assertInstanceOf(RgbColorspace::class, $result->colorspace());
|
||||
//
|
||||
// $this->expectException(NotSupportedException::class);
|
||||
// $this->image->setColorspace('cmyk');
|
||||
//
|
||||
// $this->expectException(NotSupportedException::class);
|
||||
// $this->image->setColorspace(CmykColorspace::class);
|
||||
//
|
||||
// $this->expectException(NotSupportedException::class);
|
||||
// $this->image->setColorspace(new CmykColorspace());
|
||||
// }
|
||||
//
|
||||
// public function testResolution(): void
|
||||
// {
|
||||
// $result = $this->image->resolution();
|
||||
// $this->assertInstanceOf(Resolution::class, $result);
|
||||
// }
|
||||
// }
|
||||
|
@@ -19,147 +19,147 @@ use Intervention\Image\Tests\TestCase;
|
||||
* @requires extension imagick
|
||||
* @covers \Intervention\Image\Drivers\Imagick\Image
|
||||
*/
|
||||
class ImageTest extends TestCase
|
||||
{
|
||||
protected Image $image;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
// create base image
|
||||
$imagick = new Imagick();
|
||||
|
||||
// add frame
|
||||
$frame = new Imagick();
|
||||
$frame->newImage(3, 2, new ImagickPixel('red'), 'png');
|
||||
$imagick->addImage($frame);
|
||||
|
||||
// add frame
|
||||
$frame = new Imagick();
|
||||
$frame->newImage(3, 2, new ImagickPixel('green'), 'png');
|
||||
$imagick->addImage($frame);
|
||||
|
||||
// create intervention image
|
||||
$this->image = new Image($imagick);
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$this->assertInstanceOf(Image::class, $this->image);
|
||||
}
|
||||
|
||||
public function testGetFrame(): void
|
||||
{
|
||||
$this->assertInstanceOf(Frame::class, $this->image->frame());
|
||||
$this->assertInstanceOf(Frame::class, $this->image->frame(1));
|
||||
$this->expectException(AnimationException::class);
|
||||
$this->image->frame(2);
|
||||
}
|
||||
|
||||
public function testAddFrame(): void
|
||||
{
|
||||
$frame = new Imagick();
|
||||
$frame->newImage(3, 2, new ImagickPixel('blue'), 'png');
|
||||
$frame = new Frame($frame);
|
||||
|
||||
$this->assertCount(2, $this->image);
|
||||
$result = $this->image->addFrame($frame);
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
$this->assertCount(3, $this->image);
|
||||
}
|
||||
|
||||
public function testIterator(): void
|
||||
{
|
||||
foreach ($this->image as $frame) {
|
||||
$this->assertInstanceOf(Frame::class, $frame);
|
||||
}
|
||||
}
|
||||
|
||||
public function testCount(): void
|
||||
{
|
||||
$this->assertEquals(2, $this->image->count());
|
||||
$this->assertEquals(2, count($this->image));
|
||||
}
|
||||
|
||||
public function testWidth(): void
|
||||
{
|
||||
$this->assertEquals(3, $this->image->width());
|
||||
}
|
||||
|
||||
public function testHeight(): void
|
||||
{
|
||||
$this->assertEquals(2, $this->image->height());
|
||||
}
|
||||
|
||||
public function testGetSize(): void
|
||||
{
|
||||
$this->assertInstanceOf(Rectangle::class, $this->image->size());
|
||||
}
|
||||
|
||||
public function testGetColorspace(): void
|
||||
{
|
||||
$imagick = new Imagick();
|
||||
$imagick->readImageBlob($this->getTestImageData('test.jpg'));
|
||||
$image = new Image($imagick);
|
||||
$this->assertInstanceOf(RgbColorspace::class, $image->colorspace());
|
||||
|
||||
$imagick = new Imagick();
|
||||
$imagick->readImageBlob($this->getTestImageData('cmyk.jpg'));
|
||||
$image = new Image($imagick);
|
||||
$this->assertInstanceOf(CmykColorspace::class, $image->colorspace());
|
||||
}
|
||||
|
||||
public function testSetColorspace(): void
|
||||
{
|
||||
$result = $this->image->setColorspace('rgb');
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
$this->assertInstanceOf(RgbColorspace::class, $result->colorspace());
|
||||
|
||||
$result = $this->image->setColorspace(RgbColorspace::class);
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
$this->assertInstanceOf(RgbColorspace::class, $result->colorspace());
|
||||
|
||||
$result = $this->image->setColorspace(new RgbColorspace());
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
$this->assertInstanceOf(RgbColorspace::class, $result->colorspace());
|
||||
|
||||
$result = $this->image->setColorspace('cmyk');
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
$this->assertInstanceOf(CmykColorspace::class, $result->colorspace());
|
||||
|
||||
$result = $this->image->setColorspace(CmykColorspace::class);
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
$this->assertInstanceOf(CmykColorspace::class, $result->colorspace());
|
||||
|
||||
$result = $this->image->setColorspace(new CmykColorspace());
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
$this->assertInstanceOf(CmykColorspace::class, $result->colorspace());
|
||||
}
|
||||
|
||||
public function testSetGetProfile(): void
|
||||
{
|
||||
$imagick = new Imagick();
|
||||
$imagick->readImageBlob($this->getTestImageData('test.jpg'));
|
||||
$image = new Image($imagick);
|
||||
$result = $image->profile();
|
||||
$this->assertInstanceOf(Profile::class, $result);
|
||||
$result = $image->setProfile($result);
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
}
|
||||
|
||||
public function testRemoveProfile(): void
|
||||
{
|
||||
$imagick = new Imagick();
|
||||
$imagick->readImageBlob($this->getTestImageData('test.jpg'));
|
||||
$image = new Image($imagick);
|
||||
$result = $image->removeProfile();
|
||||
$this->assertInstanceOf(Image::class, $result);
|
||||
$this->expectException(ColorException::class);
|
||||
$image->profile();
|
||||
}
|
||||
|
||||
public function testResolution(): void
|
||||
{
|
||||
$result = $this->image->resolution();
|
||||
$this->assertInstanceOf(Resolution::class, $result);
|
||||
}
|
||||
}
|
||||
// class ImageTest extends TestCase
|
||||
// {
|
||||
// protected Image $image;
|
||||
//
|
||||
// protected function setUp(): void
|
||||
// {
|
||||
// // create base image
|
||||
// $imagick = new Imagick();
|
||||
//
|
||||
// // add frame
|
||||
// $frame = new Imagick();
|
||||
// $frame->newImage(3, 2, new ImagickPixel('red'), 'png');
|
||||
// $imagick->addImage($frame);
|
||||
//
|
||||
// // add frame
|
||||
// $frame = new Imagick();
|
||||
// $frame->newImage(3, 2, new ImagickPixel('green'), 'png');
|
||||
// $imagick->addImage($frame);
|
||||
//
|
||||
// // create intervention image
|
||||
// $this->image = new Image($imagick);
|
||||
// }
|
||||
//
|
||||
// public function testConstructor(): void
|
||||
// {
|
||||
// $this->assertInstanceOf(Image::class, $this->image);
|
||||
// }
|
||||
//
|
||||
// public function testGetFrame(): void
|
||||
// {
|
||||
// $this->assertInstanceOf(Frame::class, $this->image->frame());
|
||||
// $this->assertInstanceOf(Frame::class, $this->image->frame(1));
|
||||
// $this->expectException(AnimationException::class);
|
||||
// $this->image->frame(2);
|
||||
// }
|
||||
//
|
||||
// public function testAddFrame(): void
|
||||
// {
|
||||
// $frame = new Imagick();
|
||||
// $frame->newImage(3, 2, new ImagickPixel('blue'), 'png');
|
||||
// $frame = new Frame($frame);
|
||||
//
|
||||
// $this->assertCount(2, $this->image);
|
||||
// $result = $this->image->addFrame($frame);
|
||||
// $this->assertInstanceOf(Image::class, $result);
|
||||
// $this->assertCount(3, $this->image);
|
||||
// }
|
||||
//
|
||||
// public function testIterator(): void
|
||||
// {
|
||||
// foreach ($this->image as $frame) {
|
||||
// $this->assertInstanceOf(Frame::class, $frame);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public function testCount(): void
|
||||
// {
|
||||
// $this->assertEquals(2, $this->image->count());
|
||||
// $this->assertEquals(2, count($this->image));
|
||||
// }
|
||||
//
|
||||
// public function testWidth(): void
|
||||
// {
|
||||
// $this->assertEquals(3, $this->image->width());
|
||||
// }
|
||||
//
|
||||
// public function testHeight(): void
|
||||
// {
|
||||
// $this->assertEquals(2, $this->image->height());
|
||||
// }
|
||||
//
|
||||
// public function testGetSize(): void
|
||||
// {
|
||||
// $this->assertInstanceOf(Rectangle::class, $this->image->size());
|
||||
// }
|
||||
//
|
||||
// public function testGetColorspace(): void
|
||||
// {
|
||||
// $imagick = new Imagick();
|
||||
// $imagick->readImageBlob($this->getTestImageData('test.jpg'));
|
||||
// $image = new Image($imagick);
|
||||
// $this->assertInstanceOf(RgbColorspace::class, $image->colorspace());
|
||||
//
|
||||
// $imagick = new Imagick();
|
||||
// $imagick->readImageBlob($this->getTestImageData('cmyk.jpg'));
|
||||
// $image = new Image($imagick);
|
||||
// $this->assertInstanceOf(CmykColorspace::class, $image->colorspace());
|
||||
// }
|
||||
//
|
||||
// public function testSetColorspace(): void
|
||||
// {
|
||||
// $result = $this->image->setColorspace('rgb');
|
||||
// $this->assertInstanceOf(Image::class, $result);
|
||||
// $this->assertInstanceOf(RgbColorspace::class, $result->colorspace());
|
||||
//
|
||||
// $result = $this->image->setColorspace(RgbColorspace::class);
|
||||
// $this->assertInstanceOf(Image::class, $result);
|
||||
// $this->assertInstanceOf(RgbColorspace::class, $result->colorspace());
|
||||
//
|
||||
// $result = $this->image->setColorspace(new RgbColorspace());
|
||||
// $this->assertInstanceOf(Image::class, $result);
|
||||
// $this->assertInstanceOf(RgbColorspace::class, $result->colorspace());
|
||||
//
|
||||
// $result = $this->image->setColorspace('cmyk');
|
||||
// $this->assertInstanceOf(Image::class, $result);
|
||||
// $this->assertInstanceOf(CmykColorspace::class, $result->colorspace());
|
||||
//
|
||||
// $result = $this->image->setColorspace(CmykColorspace::class);
|
||||
// $this->assertInstanceOf(Image::class, $result);
|
||||
// $this->assertInstanceOf(CmykColorspace::class, $result->colorspace());
|
||||
//
|
||||
// $result = $this->image->setColorspace(new CmykColorspace());
|
||||
// $this->assertInstanceOf(Image::class, $result);
|
||||
// $this->assertInstanceOf(CmykColorspace::class, $result->colorspace());
|
||||
// }
|
||||
//
|
||||
// public function testSetGetProfile(): void
|
||||
// {
|
||||
// $imagick = new Imagick();
|
||||
// $imagick->readImageBlob($this->getTestImageData('test.jpg'));
|
||||
// $image = new Image($imagick);
|
||||
// $result = $image->profile();
|
||||
// $this->assertInstanceOf(Profile::class, $result);
|
||||
// $result = $image->setProfile($result);
|
||||
// $this->assertInstanceOf(Image::class, $result);
|
||||
// }
|
||||
//
|
||||
// public function testRemoveProfile(): void
|
||||
// {
|
||||
// $imagick = new Imagick();
|
||||
// $imagick->readImageBlob($this->getTestImageData('test.jpg'));
|
||||
// $image = new Image($imagick);
|
||||
// $result = $image->removeProfile();
|
||||
// $this->assertInstanceOf(Image::class, $result);
|
||||
// $this->expectException(ColorException::class);
|
||||
// $image->profile();
|
||||
// }
|
||||
//
|
||||
// public function testResolution(): void
|
||||
// {
|
||||
// $result = $this->image->resolution();
|
||||
// $this->assertInstanceOf(Resolution::class, $result);
|
||||
// }
|
||||
// }
|
||||
|
47
tests/FileTest.php
Normal file
47
tests/FileTest.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Tests;
|
||||
|
||||
use Intervention\Image\File;
|
||||
|
||||
/**
|
||||
* @covers \Intervention\Image\File
|
||||
*/
|
||||
class FileTest extends TestCase
|
||||
{
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$file = new File('foo');
|
||||
$this->assertInstanceOf(File::class, $file);
|
||||
}
|
||||
|
||||
public function testSave(): void
|
||||
{
|
||||
$filename = __DIR__ . '/file_' . strval(hrtime(true)) . '.test';
|
||||
$file = new File('foo');
|
||||
$file->save($filename);
|
||||
$this->assertTrue(file_exists($filename));
|
||||
unlink($filename);
|
||||
}
|
||||
|
||||
public function testToString(): void
|
||||
{
|
||||
$file = new File('foo');
|
||||
$string = $file->toString();
|
||||
$this->assertEquals('foo', $string);
|
||||
$this->assertEquals('foo', (string) $string);
|
||||
}
|
||||
|
||||
public function testToFilePointer(): void
|
||||
{
|
||||
$file = new File('foo');
|
||||
$fp = $file->toFilePointer();
|
||||
$this->assertIsResource($fp);
|
||||
}
|
||||
|
||||
public function testSize(): void
|
||||
{
|
||||
$file = new File('foo');
|
||||
$this->assertEquals(3, $file->size());
|
||||
}
|
||||
}
|
@@ -429,8 +429,8 @@ class RectangleResizerTest extends TestCase
|
||||
$resized = $resizer->crop($origin, $position);
|
||||
$this->assertEquals($result->width(), $resized->width());
|
||||
$this->assertEquals($result->height(), $resized->height());
|
||||
$this->assertEquals($result->getPivot()->x(), $resized->pivot()->x());
|
||||
$this->assertEquals($result->getPivot()->y(), $resized->pivot()->y());
|
||||
$this->assertEquals($result->pivot()->x(), $resized->pivot()->x());
|
||||
$this->assertEquals($result->pivot()->y(), $resized->pivot()->y());
|
||||
}
|
||||
|
||||
public function cropDataProvider(): array
|
||||
|
@@ -2,7 +2,8 @@
|
||||
|
||||
namespace Intervention\Image\Tests;
|
||||
|
||||
use Intervention\Image\Exceptions\ConfigurationException;
|
||||
use Intervention\Image\Drivers\Gd\Driver as GdDriver;
|
||||
use Intervention\Image\Drivers\Imagick\Driver as ImagickDriver;
|
||||
use Intervention\Image\ImageManager;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
|
||||
@@ -13,16 +14,19 @@ class ImageManagerTest extends TestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
$manager = new ImageManager(driver: 'gd');
|
||||
$manager = new ImageManager(new GdDriver());
|
||||
$this->assertInstanceOf(ImageManager::class, $manager);
|
||||
|
||||
$this->expectException(ConfigurationException::class);
|
||||
$manager = new ImageManager('foo');
|
||||
$manager = new ImageManager(GdDriver::class);
|
||||
$this->assertInstanceOf(ImageManager::class, $manager);
|
||||
}
|
||||
|
||||
public function testWithDriver(): void
|
||||
{
|
||||
$manager = ImageManager::withDriver('gd');
|
||||
$manager = ImageManager::withDriver(new GdDriver());
|
||||
$this->assertInstanceOf(ImageManager::class, $manager);
|
||||
|
||||
$manager = ImageManager::withDriver(GdDriver::class);
|
||||
$this->assertInstanceOf(ImageManager::class, $manager);
|
||||
}
|
||||
|
||||
@@ -38,7 +42,7 @@ class ImageManagerTest extends TestCase
|
||||
/** @requires extension gd */
|
||||
public function testCreateGd()
|
||||
{
|
||||
$manager = new ImageManager('gd');
|
||||
$manager = new ImageManager(GdDriver::class);
|
||||
$image = $manager->create(5, 4);
|
||||
$this->assertInstanceOf(ImageInterface::class, $image);
|
||||
}
|
||||
@@ -46,7 +50,7 @@ class ImageManagerTest extends TestCase
|
||||
/** @requires extension gd */
|
||||
public function testReadGd()
|
||||
{
|
||||
$manager = new ImageManager('gd');
|
||||
$manager = new ImageManager(GdDriver::class);
|
||||
$image = $manager->read(__DIR__ . '/images/red.gif');
|
||||
$this->assertInstanceOf(ImageInterface::class, $image);
|
||||
}
|
||||
@@ -54,7 +58,7 @@ class ImageManagerTest extends TestCase
|
||||
/** @requires extension imagick */
|
||||
public function testCreateImagick()
|
||||
{
|
||||
$manager = new ImageManager('imagick');
|
||||
$manager = new ImageManager(ImagickDriver::class);
|
||||
$image = $manager->create(5, 4);
|
||||
$this->assertInstanceOf(ImageInterface::class, $image);
|
||||
}
|
||||
@@ -62,7 +66,7 @@ class ImageManagerTest extends TestCase
|
||||
/** @requires extension imagick */
|
||||
public function testReadImagick()
|
||||
{
|
||||
$manager = new ImageManager('imagick');
|
||||
$manager = new ImageManager(ImagickDriver::class);
|
||||
$image = $manager->read(__DIR__ . '/images/red.gif');
|
||||
$this->assertInstanceOf(ImageInterface::class, $image);
|
||||
}
|
||||
|
136
tests/ImageTest.php
Normal file
136
tests/ImageTest.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Tests;
|
||||
|
||||
use Intervention\Image\Colors\Rgb\Colorspace;
|
||||
use Intervention\Image\EncodedImage;
|
||||
use Intervention\Image\Image;
|
||||
use Intervention\Image\Interfaces\CollectionInterface;
|
||||
use Intervention\Image\Interfaces\CoreInterface;
|
||||
use Intervention\Image\Interfaces\DriverInterface;
|
||||
use Intervention\Image\Interfaces\EncodedImageInterface;
|
||||
use Intervention\Image\Interfaces\EncoderInterface;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
use Intervention\Image\Interfaces\ModifierInterface;
|
||||
use Intervention\Image\Interfaces\SizeInterface;
|
||||
use Intervention\Image\Modifiers\GreyscaleModifier;
|
||||
use Mockery;
|
||||
|
||||
class ImageTest extends TestCase
|
||||
{
|
||||
protected $modifier_mock;
|
||||
protected $encoder_mock;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$modifier = Mockery::mock(ModifierInterface::class);
|
||||
$modifier->shouldReceive('apply')->andReturn(
|
||||
Mockery::mock(ImageInterface::class)
|
||||
);
|
||||
|
||||
$encoder = Mockery::mock(EncoderInterface::class);
|
||||
$encoder->shouldReceive('encode')->andReturn(
|
||||
new EncodedImage('foo')
|
||||
);
|
||||
|
||||
$this->encoder_mock = $encoder;
|
||||
$this->modifier_mock = $modifier;
|
||||
}
|
||||
|
||||
private function testImage(): Image
|
||||
{
|
||||
$core = Mockery::mock(CoreInterface::class);
|
||||
$core->shouldReceive('width')->andReturn(300);
|
||||
$core->shouldReceive('height')->andReturn(200);
|
||||
$core->shouldReceive('count')->andReturn(12);
|
||||
$core->shouldReceive('loops')->andReturn(12);
|
||||
$core->shouldReceive('colorspace')->andReturn(new Colorspace());
|
||||
$core->shouldReceive('resolve')->andReturn(new GreyscaleModifier());
|
||||
|
||||
$driver = Mockery::mock(DriverInterface::class);
|
||||
$driver->shouldReceive('resolve')->with($this->modifier_mock)->andReturn($this->modifier_mock);
|
||||
$driver->shouldReceive('resolve')->with($this->encoder_mock)->andReturn($this->encoder_mock);
|
||||
|
||||
$exif = Mockery::mock(CollectionInterface::class);
|
||||
|
||||
return new Image($driver, $core, $exif);
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$image = $this->testImage();
|
||||
$this->assertInstanceOf(Image::class, $image);
|
||||
}
|
||||
|
||||
public function testDriver(): void
|
||||
{
|
||||
$image = $this->testImage();
|
||||
$this->assertInstanceOf(DriverInterface::class, $image->driver());
|
||||
}
|
||||
|
||||
public function testCore(): void
|
||||
{
|
||||
$image = $this->testImage();
|
||||
$this->assertInstanceOf(CoreInterface::class, $image->core());
|
||||
}
|
||||
|
||||
public function testWidthHeightSize(): void
|
||||
{
|
||||
$image = $this->testImage();
|
||||
$this->assertEquals(300, $image->width());
|
||||
$this->assertEquals(200, $image->height());
|
||||
$this->assertInstanceOf(SizeInterface::class, $image->size());
|
||||
$this->assertEquals(300, $image->size()->width());
|
||||
$this->assertEquals(200, $image->size()->height());
|
||||
}
|
||||
|
||||
public function testCount(): void
|
||||
{
|
||||
$image = $this->testImage();
|
||||
$this->assertEquals(12, $image->count());
|
||||
}
|
||||
|
||||
public function testGetIterator(): void
|
||||
{
|
||||
$image = $this->testImage();
|
||||
$this->assertInstanceOf(CoreInterface::class, $image->getIterator());
|
||||
}
|
||||
|
||||
public function testIsAnimated(): void
|
||||
{
|
||||
$image = $this->testImage();
|
||||
$this->assertTrue($image->isAnimated());
|
||||
}
|
||||
|
||||
public function testLoops(): void
|
||||
{
|
||||
$image = $this->testImage();
|
||||
$this->assertEquals(12, $image->loops());
|
||||
}
|
||||
|
||||
public function testColorspace(): void
|
||||
{
|
||||
$image = $this->testImage();
|
||||
$this->assertInstanceOf(Colorspace::class, $image->colorspace());
|
||||
}
|
||||
|
||||
public function testExif(): void
|
||||
{
|
||||
$image = $this->testImage();
|
||||
$this->assertInstanceOf(CollectionInterface::class, $image->exif());
|
||||
}
|
||||
|
||||
public function testModify(): void
|
||||
{
|
||||
$image = $this->testImage();
|
||||
$result = $image->modify($this->modifier_mock);
|
||||
$this->assertInstanceOf(ImageInterface::class, $result);
|
||||
}
|
||||
|
||||
public function testEncode(): void
|
||||
{
|
||||
$image = $this->testImage();
|
||||
$result = $image->encode($this->encoder_mock);
|
||||
$this->assertInstanceOf(EncodedImageInterface::class, $result);
|
||||
}
|
||||
}
|
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Intervention\Image\Tests;
|
||||
|
||||
use Intervention\Image\Drivers\Gd\Modifiers\GreyscaleModifier;
|
||||
use Intervention\Image\Modifiers\GreyscaleModifier;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
use Intervention\Image\Interfaces\ModifierInterface;
|
||||
use Intervention\Image\ModifierStack;
|
||||
|
@@ -2,16 +2,17 @@
|
||||
|
||||
namespace Intervention\Image\Tests\Traits;
|
||||
|
||||
use Intervention\Image\Collection;
|
||||
use Intervention\Image\Drivers\Gd\Core;
|
||||
use Intervention\Image\Drivers\Gd\Decoders\FilePathImageDecoder;
|
||||
use Intervention\Image\Drivers\Gd\Driver;
|
||||
use Intervention\Image\Drivers\Gd\Frame;
|
||||
use Intervention\Image\Drivers\Gd\Image;
|
||||
use Intervention\Image\Image;
|
||||
|
||||
trait CanCreateGdTestImage
|
||||
{
|
||||
public function createTestImage($filename = 'test.jpg'): Image
|
||||
{
|
||||
return $this->createWithImageDecoder()->handle(
|
||||
return (new FilePathImageDecoder())->handle(
|
||||
$this->getTestImagePath($filename)
|
||||
);
|
||||
}
|
||||
@@ -24,15 +25,14 @@ trait CanCreateGdTestImage
|
||||
imagefill($gd2, 0, 0, imagecolorallocate($gd1, 0, 255, 0));
|
||||
$gd3 = imagecreatetruecolor(3, 2);
|
||||
imagefill($gd3, 0, 0, imagecolorallocate($gd1, 0, 0, 255));
|
||||
return new Image(new Collection([
|
||||
new Frame($gd1),
|
||||
new Frame($gd2),
|
||||
new Frame($gd3),
|
||||
]));
|
||||
}
|
||||
|
||||
protected function createWithImageDecoder(): FilePathImageDecoder
|
||||
{
|
||||
return new FilePathImageDecoder();
|
||||
return new Image(
|
||||
new Driver(),
|
||||
new Core([
|
||||
new Frame($gd1),
|
||||
new Frame($gd2),
|
||||
new Frame($gd3),
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -3,19 +3,14 @@
|
||||
namespace Intervention\Image\Tests\Traits;
|
||||
|
||||
use Intervention\Image\Drivers\Imagick\Decoders\FilePathImageDecoder;
|
||||
use Intervention\Image\Drivers\Imagick\Image;
|
||||
use Intervention\Image\Image;
|
||||
|
||||
trait CanCreateImagickTestImage
|
||||
{
|
||||
public function createTestImage($filename = 'test.jpg'): Image
|
||||
{
|
||||
return $this->createWithImageDecoder()->handle(
|
||||
return (new FilePathImageDecoder())->handle(
|
||||
sprintf('%s/../images/%s', __DIR__, $filename)
|
||||
);
|
||||
}
|
||||
|
||||
protected function createWithImageDecoder(): FilePathImageDecoder
|
||||
{
|
||||
return new FilePathImageDecoder();
|
||||
}
|
||||
}
|
||||
|
@@ -23,11 +23,11 @@ class LineTest extends TestCase
|
||||
public function testSetGetPosition(): void
|
||||
{
|
||||
$line = new Line('foo');
|
||||
$this->assertEquals(0, $line->getPosition()->x());
|
||||
$this->assertEquals(0, $line->getPosition()->y());
|
||||
$this->assertEquals(0, $line->position()->x());
|
||||
$this->assertEquals(0, $line->position()->y());
|
||||
|
||||
$line->setPosition(new Point(10, 11));
|
||||
$this->assertEquals(10, $line->getPosition()->x());
|
||||
$this->assertEquals(11, $line->getPosition()->y());
|
||||
$this->assertEquals(10, $line->position()->x());
|
||||
$this->assertEquals(11, $line->position()->y());
|
||||
}
|
||||
}
|
||||
|
@@ -36,9 +36,9 @@ class TextBlockTest extends TestCase
|
||||
public function testGetLine(): void
|
||||
{
|
||||
$block = $this->getTestBlock();
|
||||
$this->assertEquals('foo', $block->getLine(0));
|
||||
$this->assertEquals('FooBar', $block->getLine(1));
|
||||
$this->assertEquals('bar', $block->getLine(2));
|
||||
$this->assertEquals('foo', $block->line(0));
|
||||
$this->assertEquals('FooBar', $block->line(1));
|
||||
$this->assertEquals('bar', $block->line(2));
|
||||
}
|
||||
|
||||
public function testLongestLine(): void
|
||||
@@ -65,12 +65,12 @@ class TextBlockTest extends TestCase
|
||||
);
|
||||
|
||||
$font->shouldReceive('leadingInPixels')->andReturn(30);
|
||||
$font->shouldReceive('getAlign')->andReturn('left');
|
||||
$font->shouldReceive('getValign')->andReturn('bottom');
|
||||
$font->shouldReceive('getAngle')->andReturn(0);
|
||||
$font->shouldReceive('alignment')->andReturn('left');
|
||||
$font->shouldReceive('valignment')->andReturn('bottom');
|
||||
$font->shouldReceive('angle')->andReturn(0);
|
||||
$font->shouldReceive('capHeight')->andReturn(22);
|
||||
|
||||
$box = $block->getBoundingBox($font, new Point(10, 15));
|
||||
$box = $block->boundingBox($font, new Point(10, 15));
|
||||
$this->assertEquals(300, $box->width());
|
||||
$this->assertEquals(82, $box->height());
|
||||
$this->assertEquals(10, $box->pivot()->x());
|
||||
|
Reference in New Issue
Block a user