ImageManipulation   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 2
eloc 7
dl 0
loc 32
rs 10
c 1
b 1
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A imageCopyMergeAlpha() 0 26 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Minepic\Image;
6
7
use Minepic\Image\Exceptions\ImageTrueColorCreationFailedException;
8
9
trait ImageManipulation
10
{
11
    /**
12
     * @see https://www.php.net/manual/en/function.imagecopymerge.php#92787
13
     * @throws ImageTrueColorCreationFailedException
14
     */
15
    protected function imageCopyMergeAlpha(
16
        \GdImage $dst_im,
17
        \GdImage $src_im,
18
        int $dst_x,
19
        int $dst_y,
20
        int $src_x,
21
        int $src_y,
22
        int $src_w,
23
        int $src_h,
24
        int $pct
25
    ): void {
26
        // creating a cut resource
27
        $cut = imagecreatetruecolor($src_w, $src_h);
28
29
        if ($cut instanceof \GdImage === false) {
30
            throw new ImageTrueColorCreationFailedException();
31
        }
32
33
        // copying relevant section from background to the cut resource
34
        imagecopy($cut, $dst_im, 0, 0, $dst_x, $dst_y, $src_w, $src_h);
35
36
        // copying relevant section from watermark to the cut resource
37
        imagecopy($cut, $src_im, 0, 0, $src_x, $src_y, $src_w, $src_h);
38
39
        // insert cut resource to destination image
40
        imagecopymerge($dst_im, $cut, $dst_x, $dst_y, 0, 0, $src_w, $src_h, $pct);
41
    }
42
}
43