-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
AssetHelper.php
71 lines (66 loc) · 2.32 KB
/
AssetHelper.php
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace Shel\Blog\Fusion\Helper;
/* *
* This script belongs to the Neos CMS plugin "Shel.Blog". *
* *
* @author Sebastian Helzle <sebastian@helzle.it> *
* */
use Neos\Flow\Annotations as Flow;
use Neos\Eel\ProtectedContextAwareInterface;
use Neos\Media\Domain\Model\AssetInterface;
use Neos\Media\Domain\Model\ImageInterface;
use Neos\Media\Domain\Model\ThumbnailConfiguration;
use Neos\Media\Domain\Service\ThumbnailService;
class AssetHelper implements ProtectedContextAwareInterface
{
/**
* @Flow\Inject
* @var ThumbnailService
*/
protected $thumbnailService;
/**
* @param AssetInterface $asset
* @param integer $width Desired width of the image
* @param integer $maximumWidth Desired maximum width of the image
* @param integer $height Desired height of the image
* @param integer $maximumHeight Desired maximum height of the image
* @param boolean $allowCropping Whether the image should be cropped if the given sizes would hurt the aspect ratio
* @param boolean $allowUpScaling Whether the resulting image size might exceed the size of the original image
* @return null|ImageInterface
* @throws \Exception
*/
public function createThumbnail(
AssetInterface $asset,
$width = null,
$maximumWidth = null,
$height = null,
$maximumHeight = null,
$allowCropping = false,
$allowUpScaling = false
)
{
$thumbnailConfiguration = new ThumbnailConfiguration(
$width,
$maximumWidth,
$height,
$maximumHeight,
$allowCropping,
$allowUpScaling
);
$thumbnailImage = $this->thumbnailService->getThumbnail($asset, $thumbnailConfiguration);
if (!$thumbnailImage instanceof ImageInterface) {
return null;
}
return $thumbnailImage;
}
/**
* All methods are considered safe
*
* @param string $methodName
* @return boolean
*/
public function allowsCallOfMethod($methodName)
{
return true;
}
}