Passed
Push — develop ( f65256...72a8b7 )
by Mykola
04:09
created

Image   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 45
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 3 1
A __construct() 0 39 2
1
<?php
2
3
/* 	Sunrise CMS - Open source CMS for widespread use.
4
    Copyright (c) 2019 Mykola Burakov ([email protected])
5
6
    See SOURCE.txt for other and additional information.
7
8
    This file is part of Sunrise CMS.
9
10
    This program is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
15
    This program is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
    GNU General Public License for more details.
19
20
    You should have received a copy of the GNU General Public License
21
    along with this program. If not, see <http://www.gnu.org/licenses/>. */
22
23
namespace Sunrise\Engine\Library;
24
25
// import the Intervention Image Manager Class
26
use Intervention\Image\ImageManagerStatic as IImage;
27
28
class Image
29
{
30
    public function __construct(string $file, int $img_width, int $img_height)
31
    {
32
        if (file_exists($_SERVER['DOCUMENT_ROOT'] . $file)) {
33
34
            // Prepare $file
35
            $this->file = $file;
0 ignored issues
show
Bug Best Practice introduced by
The property file does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
36
37
            // Prepare $img_width
38
            // self
39
40
            // Prepare $img_height
41
            // self
42
43
            // Prepare $watermark
44
            // if ($watermark) {
45
            //     $watermark = '/assets/images/watermark.png';
46
            // }
47
48
            // if (!file_exists($_SERVER['DOCUMENT_ROOT'] . '/temp')) {
49
            //     mkdir($_SERVER['DOCUMENT_ROOT'] . '/temp', 666, true);
50
            // }
51
52
            // Begin
53
54
            // open an image file
55
            $image = IImage::make($_SERVER['DOCUMENT_ROOT'] . $file)
56
                // now you are able to resize the instance
57
                ->resize($img_width, $img_height)
58
                // and insert a watermark for example
59
                // ->insert($watermark)
60
                // finally we save the image as a new file
61
                ->save($_SERVER['DOCUMENT_ROOT'] . '/temp' . $file);
62
63
            $this->image = $image;
0 ignored issues
show
Bug Best Practice introduced by
The property image does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
64
        } else {
65
            exit('Error: Could not load image ' . $file . '!');
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
66
        }
67
68
        \Zarganwar\PerformancePanel\Register::add('Sunrise\Engine\Library\Image::__construct');
69
    }
70
    public static function get()
71
    {
72
        return $this->image;
73
    }
74
}
75