-
-
Notifications
You must be signed in to change notification settings - Fork 219
/
IconThumbnailGenerator.php
62 lines (56 loc) · 2.06 KB
/
IconThumbnailGenerator.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
<?php
namespace Neos\Media\Domain\Model\ThumbnailGenerator;
/*
* This file is part of the Neos.Media package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
use Neos\Flow\Annotations as Flow;
use Neos\Media\Domain\Model\AssetInterface;
use Neos\Media\Domain\Model\Thumbnail;
use Neos\Media\Domain\Service\FileTypeIconService;
use Neos\Media\Domain\Service\ImageService;
use Neos\Media\Exception;
/**
* A generic thumbnail generator to get Icon of the given document
*/
class IconThumbnailGenerator extends AbstractThumbnailGenerator
{
/**
* The priority for this thumbnail generator.
*
* @var integer
* @api
*/
protected static $priority = 1;
/**
* @var ImageService
* @Flow\Inject
*/
protected $imageService;
/**
* @param Thumbnail $thumbnail
* @return void
* @throws Exception\NoThumbnailAvailableException
*/
public function refresh(Thumbnail $thumbnail)
{
try {
$width = $thumbnail->getConfigurationValue('width') ?: $thumbnail->getConfigurationValue('maximumWidth');
$height = $thumbnail->getConfigurationValue('height') ?: $thumbnail->getConfigurationValue('maximumHeight');
/** @var AssetInterface $asset */
$asset = $thumbnail->getOriginalAsset();
$icon = FileTypeIconService::getIcon($asset->getResource()->getFilename());
$thumbnail->setStaticResource($icon['src']);
$thumbnail->setWidth($width);
$thumbnail->setHeight($height);
} catch (\Exception $exception) {
$message = sprintf('Unable to generate thumbnail for the given image (filename: %s, SHA1: %s)', $thumbnail->getOriginalAsset()->getResource()->getFilename(), $thumbnail->getOriginalAsset()->getResource()->getSha1());
throw new Exception\NoThumbnailAvailableException($message, 1433109654, $exception);
}
}
}