DrawBoxAroundHints::draw()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 13
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 19
rs 9.8333
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AhmadMayahi\Vision\Detectors\CropHints;
6
7
use AhmadMayahi\Vision\Detectors\CropHints;
8
use AhmadMayahi\Vision\Enums\Color;
9
use AhmadMayahi\Vision\Support\Image;
10
11
class DrawBoxAroundHints
12
{
13
    public function __construct(private CropHints $cropHints, private Image $image, private int $borderColor = Color::GREEN)
14
    {
15
    }
16
17
    public function draw(): Image
18
    {
19
        /** @var \AhmadMayahi\Vision\Data\CropHints $hint */
20
        foreach ($this->cropHints->detect() as $hint) {
21
            $bounds = $hint->bounds;
22
23
            $this->image->drawPolygon([
24
                $bounds[0]->x,
25
                $bounds[0]->y,
26
                $bounds[1]->x,
27
                $bounds[1]->y,
28
                $bounds[2]->x,
29
                $bounds[2]->y,
30
                $bounds[3]->x,
31
                $bounds[3]->y,
32
            ], 4, $this->borderColor);
33
        }
34
35
        return $this->image;
36
    }
37
}
38