PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.12.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.12.1
5.12.1 5.12.0 5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / vendor / davaxi / sparkline / src / Sparkline / Picture.php
matomo / app / vendor / davaxi / sparkline / src / Sparkline Last commit date
DataTrait.php 2 years ago FormatTrait.php 6 months ago Picture.php 6 months ago PointTrait.php 2 years ago StyleTrait.php 2 years ago
Picture.php
132 lines
1 <?php
2
3 namespace Davaxi\Sparkline;
4
5 /**
6 * Class PictureTrait.
7 */
8 class Picture
9 {
10 const DOT_RADIUS_TO_WIDTH = 2;
11 /**
12 * @var resource
13 */
14 protected $resource;
15 /**
16 * @var int
17 */
18 protected $height;
19 /**
20 * @var int
21 */
22 protected $width;
23 /**
24 * Picture constructor.
25 * @param int $width
26 * @param int $height
27 */
28 public function __construct(int $width, int $height)
29 {
30 $this->width = $width;
31 $this->height = $height;
32 $this->resource = imagecreatetruecolor($width, $height);
33 }
34 /**
35 * @param array $setColor
36 *
37 * @return int
38 */
39 protected function getBackground(array $setColor = []) : int
40 {
41 if ($setColor) {
42 return imagecolorallocate($this->resource, $setColor[0], $setColor[1], $setColor[2]);
43 }
44 return imagecolorallocatealpha($this->resource, 0, 0, 0, 127);
45 }
46 /**
47 * @param array $lineColor
48 *
49 * @return int
50 */
51 public function getLineColor(array $lineColor) : int
52 {
53 return imagecolorallocate($this->resource, $lineColor[0], $lineColor[1], $lineColor[2]);
54 }
55 /**
56 * @param array $backgroundColor
57 */
58 public function applyBackground(array $backgroundColor)
59 {
60 imagesavealpha($this->resource, \true);
61 imagefill($this->resource, 0, 0, $this->getBackground($backgroundColor));
62 }
63 /**
64 * @param int $lineThickness
65 */
66 public function applyThickness(int $lineThickness)
67 {
68 imagesetthickness($this->resource, $lineThickness);
69 }
70 /**
71 * @param array $polygon
72 * @param array $fillColor
73 * @param int $count
74 */
75 public function applyPolygon(array $polygon, array $fillColor, int $count)
76 {
77 if (!$fillColor) {
78 return;
79 }
80 $fillColor = imagecolorallocate($this->resource, $fillColor[0], $fillColor[1], $fillColor[2]);
81 if (version_compare(\PHP_VERSION, '8.1.0') === -1) {
82 imagefilledpolygon($this->resource, $polygon, $count + 2, $fillColor);
83 } else {
84 imagefilledpolygon($this->resource, $polygon, $fillColor);
85 }
86 }
87 /**
88 * @param array $line
89 * @param array $lineColor
90 */
91 public function applyLine(array $line, array $lineColor)
92 {
93 $lineColor = $this->getLineColor($lineColor);
94 foreach ($line as $coordinates) {
95 list($pictureX1, $pictureY1, $pictureX2, $pictureY2) = $coordinates;
96 imageline($this->resource, $pictureX1, $pictureY1, $pictureX2, $pictureY2, $lineColor);
97 }
98 }
99 /**
100 * @param int $positionX
101 * @param int $positionY
102 * @param float $radius
103 * @param array $color
104 */
105 public function applyDot(int $positionX, int $positionY, float $radius, array $color)
106 {
107 if (!$color || !$radius) {
108 return;
109 }
110 $minimumColor = imagecolorallocate($this->resource, $color[0], $color[1], $color[2]);
111 $dotDiameter = (int) round($radius * static::DOT_RADIUS_TO_WIDTH);
112 imagefilledellipse($this->resource, $positionX, $positionY, $dotDiameter, $dotDiameter, $minimumColor);
113 }
114 /**
115 * @param int $width
116 * @param int $height
117 *
118 * @return resource
119 */
120 public function generate(int $width, int $height)
121 {
122 $sparkline = imagecreatetruecolor($width, $height);
123 imagealphablending($sparkline, \false);
124 imagecopyresampled($sparkline, $this->resource, 0, 0, 0, 0, $width, $height, $this->width, $this->height);
125 imagesavealpha($sparkline, \true);
126 if (\PHP_VERSION < 80000) {
127 imagedestroy($this->resource);
128 }
129 return $sparkline;
130 }
131 }
132