diff --git a/src/Driver.php b/src/Driver.php index 140da33..c0b6bda 100644 --- a/src/Driver.php +++ b/src/Driver.php @@ -4,7 +4,6 @@ namespace Intervention\Image\Drivers\Vips; -use Intervention\Image\Decoders\BinaryImageDecoder; use Intervention\Image\Drivers\AbstractDriver; use Intervention\Image\Exceptions\DriverException; use Intervention\Image\Exceptions\NotSupportedException; @@ -12,7 +11,6 @@ use Intervention\Image\FileExtension; use Intervention\Image\Format; use Intervention\Image\Image; -use Intervention\Image\InputHandler; use Intervention\Image\Interfaces\DriverInterface; use Intervention\Image\Interfaces\FrameInterface; use Intervention\Image\Interfaces\ImageInterface; @@ -110,30 +108,31 @@ public function __invoke(): ImageInterface } /** + * @param string $shape * @param array $attributes - * + * @param int $width + * @param int $height * @throws RuntimeException + * @return VipsImage */ - public static function createShape(string $shape, array $attributes, int $width, int $height): ImageInterface + public static function createShape(string $shape, array $attributes, int $width, int $height): VipsImage { $xmlAttributes = implode( ' ', array_map( - fn ($key, $value) => sprintf('%s="%s"', $key, htmlspecialchars((string) $value)), + fn($key, $value) => sprintf('%s="%s"', $key, htmlspecialchars((string) $value)), array_keys($attributes), $attributes ) ); - $svg = << - <{$shape} {$xmlAttributes} /> - -EOL; + $svg = '' . + '<' . $shape . ' ' . $xmlAttributes . ' />' . + ''; try { - return InputHandler::withDecoders([new BinaryImageDecoder()], new self())->handle($svg); - } catch (\Exception $e) { + return VipsImage::svgload_buffer($svg); + } catch (VipsException $e) { throw new RuntimeException('Could not create shape: ' . $e->getMessage(), previous: $e); } } diff --git a/src/Modifiers/DrawBezierModifier.php b/src/Modifiers/DrawBezierModifier.php index 8486153..cb8a4e6 100644 --- a/src/Modifiers/DrawBezierModifier.php +++ b/src/Modifiers/DrawBezierModifier.php @@ -32,7 +32,7 @@ public function apply(ImageInterface $image): ImageInterface }; }, $chunks, array_keys($chunks))); - $polygon = Driver::createShape( + $bezier = Driver::createShape( 'path', [ 'd' => $points, @@ -47,7 +47,7 @@ public function apply(ImageInterface $image): ImageInterface $frames = []; foreach ($image as $frame) { $frames[] = $frame->setNative( - $frame->native()->composite($polygon->core()->native(), [BlendMode::OVER]) + $frame->native()->composite($bezier, [BlendMode::OVER]) ); } diff --git a/src/Modifiers/DrawEllipseModifier.php b/src/Modifiers/DrawEllipseModifier.php index be92ff3..76571ca 100644 --- a/src/Modifiers/DrawEllipseModifier.php +++ b/src/Modifiers/DrawEllipseModifier.php @@ -41,7 +41,7 @@ public function apply(ImageInterface $image): ImageInterface $frames = []; foreach ($image as $frame) { $frames[] = $frame->setNative( - $frame->native()->composite($ellipse->core()->native(), [BlendMode::OVER]) + $frame->native()->composite($ellipse, [BlendMode::OVER]) ); } diff --git a/src/Modifiers/DrawLineModifier.php b/src/Modifiers/DrawLineModifier.php index a27f1fc..4ca2237 100644 --- a/src/Modifiers/DrawLineModifier.php +++ b/src/Modifiers/DrawLineModifier.php @@ -23,7 +23,7 @@ class DrawLineModifier extends GenericDrawLineModifier implements SpecializedInt */ public function apply(ImageInterface $image): ImageInterface { - $ellipse = Driver::createShape( + $line = Driver::createShape( 'line', [ 'x1' => $this->drawable->start()->x(), @@ -40,7 +40,7 @@ public function apply(ImageInterface $image): ImageInterface $frames = []; foreach ($image as $frame) { $frames[] = $frame->setNative( - $frame->native()->composite($ellipse->core()->native(), [BlendMode::OVER]) + $frame->native()->composite($line, [BlendMode::OVER]) ); } diff --git a/src/Modifiers/DrawPolygonModifier.php b/src/Modifiers/DrawPolygonModifier.php index 0a99791..594ebec 100644 --- a/src/Modifiers/DrawPolygonModifier.php +++ b/src/Modifiers/DrawPolygonModifier.php @@ -41,7 +41,7 @@ public function apply(ImageInterface $image): ImageInterface $frames = []; foreach ($image as $frame) { $frames[] = $frame->setNative( - $frame->native()->composite($polygon->core()->native(), [BlendMode::OVER]) + $frame->native()->composite($polygon, [BlendMode::OVER]) ); } diff --git a/src/Modifiers/DrawRectangleModifier.php b/src/Modifiers/DrawRectangleModifier.php index ba1c4e6..7024b9c 100644 --- a/src/Modifiers/DrawRectangleModifier.php +++ b/src/Modifiers/DrawRectangleModifier.php @@ -41,7 +41,7 @@ public function apply(ImageInterface $image): ImageInterface $frames = []; foreach ($image as $frame) { $frames[] = $frame->setNative( - $frame->native()->composite($rectangle->core()->native(), [BlendMode::OVER]) + $frame->native()->composite($rectangle, [BlendMode::OVER]) ); }