-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathCoverModifier.php
More file actions
50 lines (43 loc) · 1.28 KB
/
CoverModifier.php
File metadata and controls
50 lines (43 loc) · 1.28 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SizeInterface;
use Intervention\Image\Alignment;
use Intervention\Image\Exceptions\InvalidArgumentException;
use Intervention\Image\Size;
class CoverModifier extends SpecializableModifier
{
/**
* Create new modifier object.
*/
public function __construct(
public int $width,
public int $height,
public string|Alignment $alignment = Alignment::CENTER,
) {
//
}
/**
* Calculate crop size of the cover resizing process
*
* @throws InvalidArgumentException
*/
protected function cropSize(ImageInterface $image): SizeInterface
{
$imagesize = $image->size();
$crop = new Size($this->width, $this->height);
return $crop->contain(
$imagesize->width(),
$imagesize->height(),
)->alignPivotTo($imagesize, $this->alignment);
}
/**
* Calculate size for the resizing step of the cover modifier
*/
protected function resizeSize(SizeInterface $size): SizeInterface
{
return $size->resize($this->width, $this->height);
}
}