QuadraticBezier.php
1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace Grafika\Imagick\DrawingObject;
use Grafika\DrawingObject\QuadraticBezier as Base;
use Grafika\DrawingObjectInterface;
use Grafika\Imagick\Image;
use Grafika\ImageInterface;
/**
 * Class QuadraticBezier
 * @package Grafika
 */
class QuadraticBezier extends Base implements DrawingObjectInterface
{
    /**
     * @param ImageInterface $image
     * @return Image
     */
    public function draw($image)
    {
        // Localize vars
        $width = $image->getWidth();
        $height = $image->getHeight();
        $imagick = $image->getCore();
        $draw = new \ImagickDraw();
        $strokeColor = new \ImagickPixel($this->getColor()->getHexString());
        $fillColor = new \ImagickPixel('rgba(0,0,0,0)');
        $draw->setStrokeOpacity(1);
        $draw->setStrokeColor($strokeColor);
        $draw->setFillColor($fillColor);
        list($x1, $y1) = $this->point1;
        list($x2, $y2) = $this->control;
        list($x3, $y3) = $this->point2;
        $draw->pathStart();
        $draw->pathMoveToAbsolute($x1, $y1);
        $draw->pathCurveToQuadraticBezierAbsolute(
            $x2, $y2,
            $x3, $y3
        );
        $draw->pathFinish();
        // Render the draw commands in the ImagickDraw object
        $imagick->drawImage($draw);
        $type = $image->getType();
        $file = $image->getImageFile();
        return new Image($imagick, $file, $width, $height, $type); // Create new image with updated core
    }
}