Cheetah
PolygonShape.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use \Intervention\Image\Image;
6 use \Intervention\Image\Imagick\Color;
7 
9 {
15  public $points;
16 
22  public function __construct($points)
23  {
24  $this->points = $this->formatPoints($points);
25  }
26 
35  public function applyToImage(Image $image, $x = 0, $y = 0)
36  {
37  $polygon = new \ImagickDraw;
38 
39  // set background
40  $bgcolor = new Color($this->background);
41  $polygon->setFillColor($bgcolor->getPixel());
42 
43  // set border
44  if ($this->hasBorder()) {
45  $border_color = new Color($this->border_color);
46  $polygon->setStrokeWidth($this->border_width);
47  $polygon->setStrokeColor($border_color->getPixel());
48  }
49 
50  $polygon->polygon($this->points);
51 
52  $image->getCore()->drawImage($polygon);
53 
54  return true;
55  }
56 
63  private function formatPoints($points)
64  {
65  $ipoints = array();
66  $count = 1;
67 
68  foreach ($points as $key => $value) {
69  if ($count%2 === 0) {
70  $y = $value;
71  $ipoints[] = array('x' => $x, 'y' => $y);
72  } else {
73  $x = $value;
74  }
75  $count++;
76  }
77 
78  return $ipoints;
79  }
80 }
Intervention\Image\Imagick\Color
Definition: Color.php:6
php
Intervention\Image\AbstractShape
Definition: AbstractShape.php:6
Intervention\Image\Image\getCore
getCore()
Definition: Image.php:186
Intervention\Image\Imagick\Shapes
Definition: CircleShape.php:3
Intervention\Image\Image
Definition: Image.php:50
Intervention\Image\AbstractShape\$border_color
$border_color
Definition: AbstractShape.php:19
Intervention\Image\AbstractShape\hasBorder
hasBorder()
Definition: AbstractShape.php:67
Intervention\Image\Imagick\Shapes\PolygonShape
Definition: PolygonShape.php:9
Intervention\Image\AbstractShape\background
background($color)
Definition: AbstractShape.php:44
Intervention\Image\Imagick\Shapes\PolygonShape\__construct
__construct($points)
Definition: PolygonShape.php:22
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
Intervention\Image\Imagick\Shapes\PolygonShape\applyToImage
applyToImage(Image $image, $x=0, $y=0)
Definition: PolygonShape.php:35
Intervention\Image\Imagick\Shapes\PolygonShape\$points
$points
Definition: PolygonShape.php:15