Ellipse.php
992 字节
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
<?php
namespace Grafika\Imagick\DrawingObject;
use Grafika\DrawingObject\Ellipse as Base;
use Grafika\DrawingObjectInterface;
use Grafika\ImageInterface;
/**
 * Class Ellipse
 * @package Grafika
 */
class Ellipse extends Base implements DrawingObjectInterface
{
    /**
     * @param ImageInterface $image
     * @return ImageInterface
     */
    public function draw($image)
    {
        $strokeColor = new \ImagickPixel($this->getBorderColor()->getHexString());
        $fillColor = new \ImagickPixel($this->getFillColor()->getHexString());
        $draw = new \ImagickDraw();
        $draw->setStrokeColor($strokeColor);
        $draw->setFillColor($fillColor);
        $draw->setStrokeWidth($this->borderSize);
        list($x, $y) = $this->pos;
        $left = $x + $this->width / 2;
        $top = $y + $this->height / 2;
        $draw->ellipse($left, $top, $this->width/2, $this->height/2, 0, 360);
        $image->getCore()->drawImage($draw);
        return $image;
    }
}