mirror of
https://github.com/Intervention/image.git
synced 2025-09-02 18:32:56 +02:00
Refactor & add docblocks
This commit is contained in:
@@ -13,6 +13,11 @@ class ImageFactory implements FactoryInterface
|
|||||||
{
|
{
|
||||||
use CanHandleInput;
|
use CanHandleInput;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @see FactoryInterface::newImage()
|
||||||
|
*/
|
||||||
public function newImage(int $width, int $height): ImageInterface
|
public function newImage(int $width, int $height): ImageInterface
|
||||||
{
|
{
|
||||||
return new Image(
|
return new Image(
|
||||||
@@ -22,6 +27,11 @@ class ImageFactory implements FactoryInterface
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @see FactoryInterface::newAnimation()
|
||||||
|
*/
|
||||||
public function newAnimation(callable $callback): ImageInterface
|
public function newAnimation(callable $callback): ImageInterface
|
||||||
{
|
{
|
||||||
$frames = new Collection();
|
$frames = new Collection();
|
||||||
@@ -50,7 +60,7 @@ class ImageFactory implements FactoryInterface
|
|||||||
return new Image($frames);
|
return new Image($frames);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function newCore(int $width, int $height)
|
protected function newCore(int $width, int $height)
|
||||||
{
|
{
|
||||||
$core = imagecreatetruecolor($width, $height);
|
$core = imagecreatetruecolor($width, $height);
|
||||||
$color = imagecolorallocatealpha($core, 0, 0, 0, 127);
|
$color = imagecolorallocatealpha($core, 0, 0, 0, 127);
|
||||||
|
@@ -15,11 +15,21 @@ class ImageFactory implements FactoryInterface
|
|||||||
use CanHandleInput;
|
use CanHandleInput;
|
||||||
use CanCheckType;
|
use CanCheckType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @see FactoryInterface::newImage()
|
||||||
|
*/
|
||||||
public function newImage(int $width, int $height): ImageInterface
|
public function newImage(int $width, int $height): ImageInterface
|
||||||
{
|
{
|
||||||
return new Image($this->newCore($width, $height));
|
return new Image($this->newCore($width, $height));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @see FactoryInterface::newAnimation()
|
||||||
|
*/
|
||||||
public function newAnimation(callable $callback): ImageInterface
|
public function newAnimation(callable $callback): ImageInterface
|
||||||
{
|
{
|
||||||
$imagick = new Imagick();
|
$imagick = new Imagick();
|
||||||
@@ -51,7 +61,7 @@ class ImageFactory implements FactoryInterface
|
|||||||
return new Image($animation->imagick);
|
return new Image($animation->imagick);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function newCore(int $width, int $height)
|
protected function newCore(int $width, int $height)
|
||||||
{
|
{
|
||||||
$imagick = new Imagick();
|
$imagick = new Imagick();
|
||||||
$imagick->newImage($width, $height, new ImagickPixel('rgba(0, 0, 0, 0)'), 'png');
|
$imagick->newImage($width, $height, new ImagickPixel('rgba(0, 0, 0, 0)'), 'png');
|
||||||
|
@@ -4,5 +4,11 @@ namespace Intervention\Image\Interfaces;
|
|||||||
|
|
||||||
interface DecoderInterface
|
interface DecoderInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Decode given input either to color or image
|
||||||
|
*
|
||||||
|
* @param mixed $input
|
||||||
|
* @return ImageInterface|ColorInterface
|
||||||
|
*/
|
||||||
public function decode($input): ImageInterface|ColorInterface;
|
public function decode($input): ImageInterface|ColorInterface;
|
||||||
}
|
}
|
||||||
|
@@ -6,5 +6,11 @@ use Intervention\Image\EncodedImage;
|
|||||||
|
|
||||||
interface EncoderInterface
|
interface EncoderInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Encode given image
|
||||||
|
*
|
||||||
|
* @param ImageInterface $image
|
||||||
|
* @return EncodedImage
|
||||||
|
*/
|
||||||
public function encode(ImageInterface $image): EncodedImage;
|
public function encode(ImageInterface $image): EncodedImage;
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,20 @@ namespace Intervention\Image\Interfaces;
|
|||||||
|
|
||||||
interface FactoryInterface
|
interface FactoryInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Create new image in the given size
|
||||||
|
*
|
||||||
|
* @param int $width
|
||||||
|
* @param int $height
|
||||||
|
* @return ImageInterface
|
||||||
|
*/
|
||||||
public function newImage(int $width, int $height): ImageInterface;
|
public function newImage(int $width, int $height): ImageInterface;
|
||||||
public function newCore(int $width, int $height);
|
|
||||||
|
/**
|
||||||
|
* Create new animated image
|
||||||
|
*
|
||||||
|
* @param callable $callback
|
||||||
|
* @return ImageInterface
|
||||||
|
*/
|
||||||
|
public function newAnimation(callable $callback): ImageInterface;
|
||||||
}
|
}
|
||||||
|
@@ -4,5 +4,11 @@ namespace Intervention\Image\Interfaces;
|
|||||||
|
|
||||||
interface ModifierInterface
|
interface ModifierInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Apply modifications of the current modifier to the given image
|
||||||
|
*
|
||||||
|
* @param ImageInterface $image
|
||||||
|
* @return ImageInterface
|
||||||
|
*/
|
||||||
public function apply(ImageInterface $image): ImageInterface;
|
public function apply(ImageInterface $image): ImageInterface;
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,17 @@ namespace Intervention\Image\Interfaces;
|
|||||||
|
|
||||||
interface PointInterface
|
interface PointInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Return x position
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
public function getX(): int;
|
public function getX(): int;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return y position
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
public function getY(): int;
|
public function getY(): int;
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace Intervention\Image\Tests\Drivers\Gd;
|
namespace Intervention\Image\Tests\Drivers\Gd;
|
||||||
|
|
||||||
use GdImage;
|
|
||||||
use Intervention\Image\Drivers\Gd\Image;
|
use Intervention\Image\Drivers\Gd\Image;
|
||||||
use Intervention\Image\Drivers\Gd\ImageFactory;
|
use Intervention\Image\Drivers\Gd\ImageFactory;
|
||||||
use Intervention\Image\Tests\TestCase;
|
use Intervention\Image\Tests\TestCase;
|
||||||
@@ -30,11 +29,4 @@ class ImageFactoryTest extends TestCase
|
|||||||
$this->assertInstanceOf(Image::class, $image);
|
$this->assertInstanceOf(Image::class, $image);
|
||||||
$this->assertEquals(2, $image->count());
|
$this->assertEquals(2, $image->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNewCore(): void
|
|
||||||
{
|
|
||||||
$factory = new ImageFactory();
|
|
||||||
$core = $factory->newCore(3, 2);
|
|
||||||
$this->assertInstanceOf(GdImage::class, $core);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -31,7 +31,7 @@ class ImageFactoryTest extends TestCase
|
|||||||
$this->assertEquals(2, $image->count());
|
$this->assertEquals(2, $image->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNewCore(): void
|
protected function testNewCore(): void
|
||||||
{
|
{
|
||||||
$factory = new ImageFactory();
|
$factory = new ImageFactory();
|
||||||
$core = $factory->newCore(3, 2);
|
$core = $factory->newCore(3, 2);
|
||||||
|
Reference in New Issue
Block a user