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