mirror of
https://github.com/Intervention/image.git
synced 2025-08-22 13:32:56 +02:00
Fix code issues reported by phpstan
This commit is contained in:
@@ -68,9 +68,6 @@ class Font extends AbstractFont
|
|||||||
protected function getGdFontHeight(): int
|
protected function getGdFontHeight(): int
|
||||||
{
|
{
|
||||||
switch ($this->getGdFont()) {
|
switch ($this->getGdFont()) {
|
||||||
case 1:
|
|
||||||
return 8;
|
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
return 14;
|
return 14;
|
||||||
|
|
||||||
@@ -82,6 +79,10 @@ class Font extends AbstractFont
|
|||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
return 16;
|
return 16;
|
||||||
|
|
||||||
|
default:
|
||||||
|
case 1:
|
||||||
|
return 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace Intervention\Image\Drivers\Gd;
|
namespace Intervention\Image\Drivers\Gd;
|
||||||
|
|
||||||
use GdImage;
|
|
||||||
use Intervention\Image\Collection;
|
use Intervention\Image\Collection;
|
||||||
use Intervention\Image\Interfaces\FactoryInterface;
|
use Intervention\Image\Interfaces\FactoryInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
@@ -18,7 +17,7 @@ class ImageFactory implements FactoryInterface
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function newCore(int $width, int $height): GdImage
|
public 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);
|
||||||
|
@@ -3,9 +3,9 @@
|
|||||||
namespace Intervention\Image\Drivers\Gd\Modifiers;
|
namespace Intervention\Image\Drivers\Gd\Modifiers;
|
||||||
|
|
||||||
use Intervention\Image\Drivers\Gd\Image;
|
use Intervention\Image\Drivers\Gd\Image;
|
||||||
use Intervention\Image\Geometry\Point;
|
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Interfaces\ModifierInterface;
|
use Intervention\Image\Interfaces\ModifierInterface;
|
||||||
|
use Intervention\Image\Interfaces\PointInterface;
|
||||||
use Intervention\Image\Traits\CanResolveDriverClass;
|
use Intervention\Image\Traits\CanResolveDriverClass;
|
||||||
|
|
||||||
class PlaceModifier implements ModifierInterface
|
class PlaceModifier implements ModifierInterface
|
||||||
@@ -52,7 +52,7 @@ class PlaceModifier implements ModifierInterface
|
|||||||
return $this->resolveDriverClass('InputHandler')->handle($this->element);
|
return $this->resolveDriverClass('InputHandler')->handle($this->element);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getPosition(Image $image, Image $watermark): Point
|
protected function getPosition(ImageInterface $image, ImageInterface $watermark): PointInterface
|
||||||
{
|
{
|
||||||
$image_size = $image->getSize()->alignPivot($this->position, $this->offset_x, $this->offset_y);
|
$image_size = $image->getSize()->alignPivot($this->position, $this->offset_x, $this->offset_y);
|
||||||
$watermark_size = $watermark->getSize()->alignPivot($this->position);
|
$watermark_size = $watermark->getSize()->alignPivot($this->position);
|
||||||
|
@@ -21,17 +21,17 @@ class Color extends AbstractColor implements ColorInterface
|
|||||||
|
|
||||||
public function red(): int
|
public function red(): int
|
||||||
{
|
{
|
||||||
return round($this->pixel->getColorValue(Imagick::COLOR_RED) * 255);
|
return intval(round($this->pixel->getColorValue(Imagick::COLOR_RED) * 255));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function green(): int
|
public function green(): int
|
||||||
{
|
{
|
||||||
return round($this->pixel->getColorValue(Imagick::COLOR_GREEN) * 255);
|
return intval(round($this->pixel->getColorValue(Imagick::COLOR_GREEN) * 255));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function blue(): int
|
public function blue(): int
|
||||||
{
|
{
|
||||||
return round($this->pixel->getColorValue(Imagick::COLOR_BLUE) * 255);
|
return intval(round($this->pixel->getColorValue(Imagick::COLOR_BLUE) * 255));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function alpha(): float
|
public function alpha(): float
|
||||||
|
@@ -4,7 +4,9 @@ namespace Intervention\Image\Drivers\Imagick\Encoders;
|
|||||||
|
|
||||||
use Imagick;
|
use Imagick;
|
||||||
use Intervention\Image\Drivers\Abstract\Encoders\AbstractEncoder;
|
use Intervention\Image\Drivers\Abstract\Encoders\AbstractEncoder;
|
||||||
|
use Intervention\Image\Drivers\Imagick\Image;
|
||||||
use Intervention\Image\EncodedImage;
|
use Intervention\Image\EncodedImage;
|
||||||
|
use Intervention\Image\Exceptions\EncoderException;
|
||||||
use Intervention\Image\Interfaces\EncoderInterface;
|
use Intervention\Image\Interfaces\EncoderInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
|
|
||||||
@@ -15,6 +17,10 @@ class GifEncoder extends AbstractEncoder implements EncoderInterface
|
|||||||
$format = 'gif';
|
$format = 'gif';
|
||||||
$compression = Imagick::COMPRESSION_LZW;
|
$compression = Imagick::COMPRESSION_LZW;
|
||||||
|
|
||||||
|
if (!is_a($image, Image::class)) {
|
||||||
|
throw new EncoderException('Image does not match the current driver.');
|
||||||
|
}
|
||||||
|
|
||||||
$imagick = $image->getImagick();
|
$imagick = $image->getImagick();
|
||||||
$imagick->setFormat($format);
|
$imagick->setFormat($format);
|
||||||
$imagick->setImageFormat($format);
|
$imagick->setImageFormat($format);
|
||||||
|
@@ -5,6 +5,7 @@ namespace Intervention\Image\Drivers\Imagick;
|
|||||||
use Imagick;
|
use Imagick;
|
||||||
use ImagickDraw;
|
use ImagickDraw;
|
||||||
use Intervention\Image\Drivers\Abstract\AbstractFont;
|
use Intervention\Image\Drivers\Abstract\AbstractFont;
|
||||||
|
use Intervention\Image\Exceptions\DecoderException;
|
||||||
use Intervention\Image\Exceptions\FontException;
|
use Intervention\Image\Exceptions\FontException;
|
||||||
use Intervention\Image\Geometry\Polygon;
|
use Intervention\Image\Geometry\Polygon;
|
||||||
use Intervention\Image\Geometry\Size;
|
use Intervention\Image\Geometry\Size;
|
||||||
@@ -17,12 +18,17 @@ class Font extends AbstractFont
|
|||||||
throw new FontException('No font file specified.');
|
throw new FontException('No font file specified.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$color = $this->getColor();
|
||||||
|
if (!is_a($color, Color::class)) {
|
||||||
|
throw new DecoderException('Unable to decode font color.');
|
||||||
|
}
|
||||||
|
|
||||||
$draw = new ImagickDraw();
|
$draw = new ImagickDraw();
|
||||||
$draw->setStrokeAntialias(true);
|
$draw->setStrokeAntialias(true);
|
||||||
$draw->setTextAntialias(true);
|
$draw->setTextAntialias(true);
|
||||||
$draw->setFont($this->getFilename());
|
$draw->setFont($this->getFilename());
|
||||||
$draw->setFontSize($this->getSize());
|
$draw->setFontSize($this->getSize());
|
||||||
$draw->setFillColor($this->getColor()->getPixel());
|
$draw->setFillColor($color->getPixel());
|
||||||
$draw->setTextAlignment($this->getImagickAlign());
|
$draw->setTextAlignment($this->getImagickAlign());
|
||||||
|
|
||||||
return $draw;
|
return $draw;
|
||||||
@@ -38,11 +44,9 @@ class Font extends AbstractFont
|
|||||||
switch (strtolower($this->getAlign())) {
|
switch (strtolower($this->getAlign())) {
|
||||||
case 'center':
|
case 'center':
|
||||||
return Imagick::ALIGN_CENTER;
|
return Imagick::ALIGN_CENTER;
|
||||||
break;
|
|
||||||
|
|
||||||
case 'right':
|
case 'right':
|
||||||
return Imagick::ALIGN_RIGHT;
|
return Imagick::ALIGN_RIGHT;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Imagick::ALIGN_LEFT;
|
return Imagick::ALIGN_LEFT;
|
||||||
|
@@ -39,7 +39,7 @@ class Frame implements FrameInterface
|
|||||||
|
|
||||||
public function setDelay(float $delay): FrameInterface
|
public function setDelay(float $delay): FrameInterface
|
||||||
{
|
{
|
||||||
$this->core->setImageDelay(round($delay * 100));
|
$this->core->setImageDelay(intval(round($delay * 100)));
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,7 @@ class ImageFactory implements FactoryInterface
|
|||||||
return new Image($this->newCore($width, $height));
|
return new Image($this->newCore($width, $height));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function newCore(int $width, int $height): Imagick
|
public 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');
|
||||||
|
@@ -5,7 +5,8 @@ namespace Intervention\Image\Drivers\Imagick\Modifiers;
|
|||||||
use Imagick;
|
use Imagick;
|
||||||
use ImagickDraw;
|
use ImagickDraw;
|
||||||
use Intervention\Image\Drivers\Abstract\Modifiers\AbstractPadModifier;
|
use Intervention\Image\Drivers\Abstract\Modifiers\AbstractPadModifier;
|
||||||
use Intervention\Image\Interfaces\ColorInterface;
|
use Intervention\Image\Drivers\Imagick\Color;
|
||||||
|
use Intervention\Image\Exceptions\DecoderException;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Interfaces\ModifierInterface;
|
use Intervention\Image\Interfaces\ModifierInterface;
|
||||||
use Intervention\Image\Interfaces\SizeInterface;
|
use Intervention\Image\Interfaces\SizeInterface;
|
||||||
@@ -23,6 +24,10 @@ class PadModifier extends AbstractPadModifier implements ModifierInterface
|
|||||||
$crop = $this->getCropSize($image);
|
$crop = $this->getCropSize($image);
|
||||||
$background = $this->handleInput($this->background);
|
$background = $this->handleInput($this->background);
|
||||||
|
|
||||||
|
if (!is_a($background, Color::class)) {
|
||||||
|
throw new DecoderException('Unable to decode backgroud color.');
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($image as $frame) {
|
foreach ($image as $frame) {
|
||||||
// resize current core
|
// resize current core
|
||||||
$frame->getCore()->scaleImage(
|
$frame->getCore()->scaleImage(
|
||||||
@@ -49,7 +54,7 @@ class PadModifier extends AbstractPadModifier implements ModifierInterface
|
|||||||
return $image;
|
return $image;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function buildBaseCanvas(SizeInterface $crop, SizeInterface $resize, ColorInterface $background): Imagick
|
protected function buildBaseCanvas(SizeInterface $crop, SizeInterface $resize, Color $background): Imagick
|
||||||
{
|
{
|
||||||
// build base canvas in target size
|
// build base canvas in target size
|
||||||
$canvas = $this->imageFactory()->newCore(
|
$canvas = $this->imageFactory()->newCore(
|
||||||
|
@@ -7,6 +7,7 @@ use Intervention\Image\Drivers\Imagick\Image;
|
|||||||
use Intervention\Image\Geometry\Point;
|
use Intervention\Image\Geometry\Point;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Interfaces\ModifierInterface;
|
use Intervention\Image\Interfaces\ModifierInterface;
|
||||||
|
use Intervention\Image\Interfaces\PointInterface;
|
||||||
use Intervention\Image\Traits\CanResolveDriverClass;
|
use Intervention\Image\Traits\CanResolveDriverClass;
|
||||||
|
|
||||||
class PlaceModifier implements ModifierInterface
|
class PlaceModifier implements ModifierInterface
|
||||||
@@ -44,7 +45,7 @@ class PlaceModifier implements ModifierInterface
|
|||||||
return $this->resolveDriverClass('InputHandler')->handle($this->element);
|
return $this->resolveDriverClass('InputHandler')->handle($this->element);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getPosition(Image $image, Image $watermark): Point
|
protected function getPosition(ImageInterface $image, Image $watermark): PointInterface
|
||||||
{
|
{
|
||||||
$image_size = $image->getSize()->alignPivot($this->position, $this->offset_x, $this->offset_y);
|
$image_size = $image->getSize()->alignPivot($this->position, $this->offset_x, $this->offset_y);
|
||||||
$watermark_size = $watermark->getSize()->alignPivot($this->position);
|
$watermark_size = $watermark->getSize()->alignPivot($this->position);
|
||||||
|
@@ -3,6 +3,8 @@
|
|||||||
namespace Intervention\Image\Drivers\Imagick\Modifiers;
|
namespace Intervention\Image\Drivers\Imagick\Modifiers;
|
||||||
|
|
||||||
use Intervention\Image\Drivers\Abstract\Modifiers\AbstractRotateModifier;
|
use Intervention\Image\Drivers\Abstract\Modifiers\AbstractRotateModifier;
|
||||||
|
use Intervention\Image\Drivers\Imagick\Color;
|
||||||
|
use Intervention\Image\Exceptions\DecoderException;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Interfaces\ModifierInterface;
|
use Intervention\Image\Interfaces\ModifierInterface;
|
||||||
|
|
||||||
@@ -10,9 +12,14 @@ class RotateModifier extends AbstractRotateModifier implements ModifierInterface
|
|||||||
{
|
{
|
||||||
public function apply(ImageInterface $image): ImageInterface
|
public function apply(ImageInterface $image): ImageInterface
|
||||||
{
|
{
|
||||||
|
$background = $this->backgroundColor();
|
||||||
|
if (!is_a($background, Color::class)) {
|
||||||
|
throw new DecoderException('Unable to decode given background color.');
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($image as $frame) {
|
foreach ($image as $frame) {
|
||||||
$frame->getCore()->rotateImage(
|
$frame->getCore()->rotateImage(
|
||||||
$this->backgroundColor()->getPixel(),
|
$background->getPixel(),
|
||||||
$this->rotationAngle()
|
$this->rotationAngle()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
8
src/Exceptions/EncoderException.php
Normal file
8
src/Exceptions/EncoderException.php
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Intervention\Image\Exceptions;
|
||||||
|
|
||||||
|
class EncoderException extends \RuntimeException
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
@@ -9,6 +9,6 @@ interface ColorInterface
|
|||||||
public function blue(): int;
|
public function blue(): int;
|
||||||
public function alpha(): float;
|
public function alpha(): float;
|
||||||
public function toArray(): array;
|
public function toArray(): array;
|
||||||
public function toHex(): string;
|
public function toHex(string $prefix = ''): string;
|
||||||
public function toInt(): int;
|
public function toInt(): int;
|
||||||
}
|
}
|
||||||
|
@@ -5,4 +5,5 @@ namespace Intervention\Image\Interfaces;
|
|||||||
interface FactoryInterface
|
interface FactoryInterface
|
||||||
{
|
{
|
||||||
public function newImage(int $width, int $height): ImageInterface;
|
public function newImage(int $width, int $height): ImageInterface;
|
||||||
|
public function newCore(int $width, int $height);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user