Completed
Push — master ( 1bd7cb...6e7c5d )
by David
12s
created

Manipulator::create()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.2888
c 0
b 0
f 0
cc 5
nc 5
nop 2
1
<?php
2
3
namespace GNAHotelSolutions\ImageCacher;
4
5
class Manipulator
6
{
7
    public static function create(string $format, string $path)
8
    {
9
        if ($format === Format::JPEG) {
10
            return imagecreatefromjpeg($path);
11
        }
12
13
        if ($format === Format::PNG) {
14
            return imagecreatefrompng($path);
15
        }
16
17
        if ($format === Format::GIF) {
18
            return imagecreatefromgif($path);
19
        }
20
21
        if ($format === Format::WEBP) {
22
            return imagecreatefromwebp($path);
23
        }
24
25
        throw new \Exception("Image type [{$format}] not supported.");
26
    }
27
28
    public static function save(string $format, $layout, string $name): string
29
    {
30
        if ($format === Format::JPEG) {
31
            return imagejpeg($layout, $name);
32
        }
33
34
        if ($format === Format::PNG) {
35
            return imagepng($layout, $name);
36
        }
37
38
        if ($format === Format::GIF) {
39
            return imagegif($layout, $name);
40
        }
41
42
        if ($format === Format::WEBP) {
43
            return imagewebp($layout, $name);
44
        }
45
46
        throw new \Exception("Image type [{$format}] not supported.");
47
    }
48
}