Crop::crop()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 15
rs 10
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\Support\Image;
9
10
class Crop
11
{
12
    public function __construct(private CropHints $cropHints, private Image $image)
13
    {
14
    }
15
16
    public function crop(): Image
17
    {
18
        /** @var \AhmadMayahi\Vision\Data\CropHints $hint */
19
        foreach ($this->cropHints->detect() as $hint) {
20
            $bounds = $hint->bounds;
21
22
            $this->image->cropImage(
23
                x: $bounds[0]->x,
24
                y: $bounds[0]->y,
25
                width: $bounds[2]->x - 1,
26
                height: $bounds[2]->y - 1,
27
            );
28
        }
29
30
        return $this->image;
31
    }
32
}
33