Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/mako/pixel/image/inspectors/ColorAt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/**
* @copyright Frederic G. Østby
* @license http://www.makoframework.com/license
*/

namespace mako\pixel\image\inspectors;

use mako\pixel\image\Color;
use mako\pixel\image\geometry\Point;
use mako\pixel\image\traits\PixelValidationTrait;

/**
* Returns the color of the specified pixel.
*
* @implements InspectorInterface<Color>
*/
abstract class ColorAt implements InspectorInterface
{
use PixelValidationTrait;

/**
* Constructor.
*/
final public function __construct(
protected Point $pixel
) {
}
}
20 changes: 20 additions & 0 deletions src/mako/pixel/image/inspectors/ColorSpace.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* @copyright Frederic G. Østby
* @license http://www.makoframework.com/license
*/

namespace mako\pixel\image\inspectors;

use mako\pixel\image\ColorSpace as ColorSpaceEnum;

/**
* Returns the color space of the image.
*
* @implements InspectorInterface<ColorSpaceEnum>
*/
abstract class ColorSpace implements InspectorInterface
{

}
30 changes: 30 additions & 0 deletions src/mako/pixel/image/inspectors/TopColors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/**
* @copyright Frederic G. Østby
* @license http://www.makoframework.com/license
*/

namespace mako\pixel\image\inspectors;

use mako\pixel\image\Color;

/**
* Extracts the dominant colors from an image.
*
* Similar colors are grouped together to avoid returning multiple
* variations of the same color.
*
* @implements InspectorInterface<array<int, Color>>
*/
abstract class TopColors implements InspectorInterface
{
/**
* Constructor.
*/
final public function __construct(
protected int $limit = 5,
protected bool $ignoreTransparent = true,
) {
}
}
17 changes: 3 additions & 14 deletions src/mako/pixel/image/inspectors/gd/ColorAt.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

use GdImage;
use mako\pixel\image\Color;
use mako\pixel\image\geometry\Point;
use mako\pixel\image\inspectors\InspectorInterface;
use mako\pixel\image\inspectors\ColorAt as BaseColorAt;
use mako\pixel\image\traits\GdTrait;
use mako\pixel\image\traits\PixelValidationTrait;
use Override;
Expand All @@ -20,23 +19,13 @@
use function imagesy;

/**
* Returns the color of the specified pixel.
*
* @implements InspectorInterface<Color>
* {@inheritDoc}
*/
class ColorAt implements InspectorInterface
class ColorAt extends BaseColorAt
{
use GdTrait;
use PixelValidationTrait;

/**
* Constructor.
*/
public function __construct(
protected Point $pixel
) {
}

/**
* {@inheritDoc}
*
Expand Down
20 changes: 3 additions & 17 deletions src/mako/pixel/image/inspectors/gd/TopColors.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use GdImage;
use mako\pixel\image\Color;
use mako\pixel\image\inspectors\InspectorInterface;
use mako\pixel\image\inspectors\TopColors as BaseTopColors;
use mako\pixel\image\traits\GdTrait;
use Override;

Expand All @@ -24,14 +24,9 @@
use function usort;

/**
* Extracts the dominant colors from an image.
*
* Similar colors are grouped together to avoid returning multiple
* variations of the same color.
*
* @implements InspectorInterface<array<int, Color>>
* {@inheritDoc}
*/
class TopColors implements InspectorInterface
class TopColors extends BaseTopColors
{
use GdTrait;

Expand All @@ -41,15 +36,6 @@ class TopColors implements InspectorInterface
*/
protected const int MAX_SAMPLE_STEP = 8;

/**
* Constructor.
*/
public function __construct(
protected int $limit = 5,
protected bool $ignoreTransparent = true
) {
}

/**
* Calculates the sampling step size based on image dimensions.
*
Expand Down
17 changes: 3 additions & 14 deletions src/mako/pixel/image/inspectors/imagemagick/ColorAt.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,17 @@

use Imagick;
use mako\pixel\image\Color;
use mako\pixel\image\geometry\Point;
use mako\pixel\image\inspectors\InspectorInterface;
use mako\pixel\image\inspectors\ColorAt as BaseColorAt;
use mako\pixel\image\traits\PixelValidationTrait;
use Override;

/**
* Returns the color of the specified pixel.
*
* @implements InspectorInterface<Color>
* @inheritDoc}
*/
class ColorAt implements InspectorInterface
class ColorAt extends BaseColorAt
{
use PixelValidationTrait;

/**
* Constructor.
*/
public function __construct(
protected Point $pixel
) {
}

/**
* {@inheritDoc}
*
Expand Down
8 changes: 3 additions & 5 deletions src/mako/pixel/image/inspectors/imagemagick/ColorSpace.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use Imagick;
use mako\pixel\image\ColorSpace as ColorSpaceEnum;
use mako\pixel\image\inspectors\InspectorInterface;
use mako\pixel\image\inspectors\ColorSpace as BaseColorSpace;
use Override;
use ReflectionClass;

Expand All @@ -18,11 +18,9 @@
use function strtolower;

/**
* Returns the color space of the image.
*
* @implements InspectorInterface<ColorSpaceEnum>
* {@inheritDoc}
*/
class ColorSpace implements InspectorInterface
class ColorSpace extends BaseColorSpace
{
/**
* Returns a map of the available color spaces.
Expand Down
20 changes: 3 additions & 17 deletions src/mako/pixel/image/inspectors/imagemagick/TopColors.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,17 @@

use Imagick;
use mako\pixel\image\Color;
use mako\pixel\image\inspectors\InspectorInterface;
use mako\pixel\image\inspectors\TopColors as BaseTopColors;
use Override;

use function array_slice;
use function usort;

/**
* Extracts the dominant colors from an image.
*
* Similar colors are grouped together to avoid returning multiple
* variations of the same color.
*
* @implements InspectorInterface<array<int, Color>>
* {@inheritDoc}
*/
class TopColors implements InspectorInterface
class TopColors extends BaseTopColors
{
/**
* Constructor.
*/
public function __construct(
protected int $limit = 5,
protected bool $ignoreTransparent = true,
) {
}

/**
* {@inheritDoc}
*
Expand Down
39 changes: 39 additions & 0 deletions src/mako/pixel/image/operations/Bezier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/**
* @copyright Frederic G. Østby
* @license http://www.makoframework.com/license
*/

namespace mako\pixel\image\operations;

use InvalidArgumentException;
use mako\pixel\image\Color;
use mako\pixel\image\geometry\Point;
use mako\pixel\image\geometry\Points;

use function count;

/**
* Draws a Bézier curve on the image.
*/
abstract class Bezier implements OperationInterface
{
/**
* Constructor.
*/
final public function __construct(
protected Points $points,
protected Color $stroke,
protected int $strokeWidth = 1,
protected Point $position = new Point(0, 0)
) {
if (count($points) < 2) {
throw new InvalidArgumentException('A Bézier curve requires at least 2 points.');
}

if ($this->strokeWidth < 1) {
throw new InvalidArgumentException('Stroke width must be greater than 0.');
}
}
}
16 changes: 16 additions & 0 deletions src/mako/pixel/image/operations/Bitonal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/**
* @copyright Frederic G. Østby
* @license http://www.makoframework.com/license
*/

namespace mako\pixel\image\operations;

/**
* Turns the image into bitonal.
*/
abstract class Bitonal implements OperationInterface
{

}
28 changes: 28 additions & 0 deletions src/mako/pixel/image/operations/Border.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/**
* @copyright Frederic G. Østby
* @license http://www.makoframework.com/license
*/

namespace mako\pixel\image\operations;

use mako\pixel\image\Color;

use function max;

/**
* Adds a border to the image.
*/
abstract class Border implements OperationInterface
{
/**
* Constructor.
*/
final public function __construct(
protected Color $color = new Color(0, 0, 0),
protected int $width = 4
) {
$this->width = max(0, $this->width);
}
}
22 changes: 22 additions & 0 deletions src/mako/pixel/image/operations/Brightness.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/**
* @copyright Frederic G. Østby
* @license http://www.makoframework.com/license
*/

namespace mako\pixel\image\operations;

/**
* Adjusts the image brightness.
*/
abstract class Brightness implements OperationInterface
{
/**
* Constructor.
*/
final public function __construct(
protected int $level = 0
) {
}
}
37 changes: 37 additions & 0 deletions src/mako/pixel/image/operations/Circle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* @copyright Frederic G. Østby
* @license http://www.makoframework.com/license
*/

namespace mako\pixel\image\operations;

use InvalidArgumentException;
use mako\pixel\image\Color;
use mako\pixel\image\geometry\Point;

/**
* Draws a circle on the image.
*/
abstract class Circle implements OperationInterface
{
/**
* Constructor.
*/
final public function __construct(
protected int $radius,
protected ?Color $fill = null,
protected ?Color $stroke = null,
protected int $strokeWidth = 1,
protected Point $center = new Point(0, 0)
) {
if ($this->fill === null && $this->stroke === null) {
throw new InvalidArgumentException('A circle requires a fill, a stroke, or both.');
}

if ($this->stroke !== null && $this->strokeWidth < 1) {
throw new InvalidArgumentException('Stroke width must be greater than 0.');
}
}
}
Loading