Watermark   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 26
c 0
b 0
f 0
wmc 4
lcom 0
cbo 5
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 13 4
1
<?php
2
3
namespace yiicod\easyimage\tools;
4
5
use Exception;
6
use Imagine\Image\ManipulatorInterface;
7
use Imagine\Image\Point;
8
use yiicod\easyimage\base\ToolInterface;
9
use yiicod\easyimage\EasyImage;
10
11
/**
12
 * Class Watermark
13
 * Watermark image tool
14
 *
15
 * @author Virchenko Maksim <[email protected]>
16
 *
17
 * @package yiicod\easyimage\tools
18
 */
19
class Watermark implements ToolInterface
20
{
21
    /**
22
     * Handle image
23
     *
24
     * @param ManipulatorInterface $image
25
     * @param array $params
26
     *
27
     * @return ManipulatorInterface
28
     *
29
     * @throws Exception
30
     */
31
    public static function handle(ManipulatorInterface $image, array $params = []): ManipulatorInterface
32
    {
33
        if (false === isset($params['image'])) {
34
            throw new Exception('Param "image" is required for action "Watermark"');
35
        }
36
37
        $watermark = EasyImage::getImagine()->open($params['image'])->copy();
38
39
        return $image->paste($watermark, new Point(
40
            isset($params['offset_x']) ? $params['offset_x'] : 0,
41
            isset($params['offset_y']) ? $params['offset_y'] : 0
42
        ));
43
    }
44
}
45