Passed
Push — master ( a29299...174a4a )
by compolom
02:24
created

Imagick::flop()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Compolomus\Compomage;
4
5
use Compolomus\Compomage\Interfaces\ImageInterface;
6
7
class Imagick extends AbstractImage implements ImageInterface
8
{
9
    /**
10
     * Imagick constructor.
11
     * @param string $image
12
     * @throws \Exception
13
     */
14
    public function __construct(string $image)
15
    {
16
        $this->init($image);
17
    }
18
19
    /**
20
     * @param string $source
21
     * @return ImageInterface
22
     * @throws \Exception
23
     */
24
    protected function tmp(string $source): ImageInterface
25
    {
26
        $image = new \Imagick;
27
        if ($image->readImageBlob($source)) {
28
            if ($image->getImageAlphaChannel() !== \Imagick::ALPHACHANNEL_ACTIVATE) {
29
                $image->setImageAlphaChannel(\Imagick::ALPHACHANNEL_SET);  // 8
30
                #$image->setImageAlphaChannel(\Imagick::ALPHACHANNEL_OPAQUE); // 6
31
            }
32
        }
33
        $background = new \Imagick;
34
        $background->newImage($image->getImageWidth(), $image->getImageHeight(), new \ImagickPixel('transparent'));
35
        $background->setImageBackgroundColor(new \ImagickPixel('transparent'));
36
        $image->compositeImage($background, \imagick::COMPOSITE_OVER, 0, 0); //Imagick::COMPOSITE_DISSOLVE
37
        $this->setImage($image);
38
        $this->getImage()->setFormat('png'); // save transparent
39
        $this->setSizes();
40
41
        return $this;
42
    }
43
44
    protected function setSizes(): void
45
    {
46
        $args = $this->getImage()->getImageGeometry();
47
        $this->setWidth($args['width']);
48
        $this->setHeight($args['height']);
49
    }
50
51
    private function newImage(int $width, int $height)
0 ignored issues
show
Unused Code introduced by
The parameter $height is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

51
    private function newImage(int $width, /** @scrutinizer ignore-unused */ int $height)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $width is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

51
    private function newImage(/** @scrutinizer ignore-unused */ int $width, int $height)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
52
    {
53
        $background = new \Imagick;
54
        $background->newImage($image->getImageWidth(), $image->getImageHeight(), new \ImagickPixel('transparent'));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $image seems to be never defined.
Loading history...
55
        $background->setImageBackgroundColor(new \ImagickPixel('transparent'));
56
    }
57
58
    public function resize(int $width, int $height): ImageInterface
59
    {
60
        $this->getImage()->scaleImage($width, $height, false);
61
        $this->setSizes();
62
63
        return $this;
64
    }
65
66
    public function rotate(int $angle = 90): ImageInterface
67
    {
68
        $this->image->rotateImage(new \ImagickPixel('transparent'), $angle);
69
        $this->setSizes();
70
71
        return $this;
72
    }
73
74
    public function watermark(): ImageInterface
75
    {
76
        return $this;
77
    }
78
79
    public function flip(): ImageInterface
80
    {
81
        $this->getImage()->flipImage();
82
83
        return $this;
84
    }
85
86
    public function flop(): ImageInterface
87
    {
88
        $this->getImage()->flopImage();
89
90
        return $this;
91
    }
92
93
    public function grayscale(): ImageInterface
94
    {
95
        $this->getImage()->modulateImage(100, 0, 100);
96
97
        return $this;
98
    }
99
100
    public function crop(int $width, int $height, int $startX, int $startY): ImageInterface
101
    {
102
        $this->getImage()->cropImage($width, $height, $startX, $startY);
103
        $this->setSizes();
104
105
        return $this;
106
    }
107
108
    public function save(string $filename): bool
109
    {
110
        return true;
111
    }
112
113
    public function __toString(): string
114
    {
115
        return $this->getImage()->getImageBlob();
116
    }
117
}
118