forked from jkapuscik2/design-patterns-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImage.php
More file actions
30 lines (22 loc) · 803 Bytes
/
Image.php
File metadata and controls
30 lines (22 loc) · 803 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
namespace Structural\Facade;
use \Imagick;
use \SplFileInfo;
class Image {
private $imagick;
public function __construct () {
$this->imagick = new Imagick();
}
public function thumbnail (string $filePath, int $width, int $height) {
$this->imagick->readImage($filePath);
$this->imagick->setbackgroundcolor('rgb(0, 0, 0)');
$this->imagick->thumbnailImage($width, $height, true, true);
$fileInfo = new SplFileInfo($filePath);
$thumbPath = $fileInfo->getBasename('.' . $fileInfo->getExtension()) . '_thumb' . "." . $fileInfo->getExtension();
if (file_put_contents($thumbPath, $this->imagick)) {
return true;
} else {
throw new \Exception("Could not create thumbnail.");
}
}
}