22 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
23 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
24 use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;
25 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
85 use CompileWithRenderStatic;
92 $this->registerArgument(
'src',
'string',
'src');
93 $this->registerArgument(
'treatIdAsReference',
'bool',
'given src argument is a sys_file_reference record',
false,
false);
94 $this->registerArgument(
'image',
'object',
'image');
95 $this->registerArgument(
'crop',
'string|bool',
'overrule cropping of image (setting to FALSE disables the cropping set in FileReference)');
96 $this->registerArgument(
'cropVariant',
'string',
'select a cropping variant, in case multiple croppings have been specified or stored in FileReference',
false,
'default');
98 $this->registerArgument(
'width',
'string',
'width of the image. This can be a numeric value representing the fixed width of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.');
99 $this->registerArgument(
'height',
'string',
'height of the image. This can be a numeric value representing the fixed height of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.');
100 $this->registerArgument(
'minWidth',
'int',
'minimum width of the image');
101 $this->registerArgument(
'minHeight',
'int',
'minimum height of the image');
102 $this->registerArgument(
'maxWidth',
'int',
'maximum width of the image');
103 $this->registerArgument(
'maxHeight',
'int',
'maximum height of the image');
104 $this->registerArgument(
'absolute',
'bool',
'Force absolute URL',
false,
false);
116 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
118 $src = $arguments[
'src'];
119 $image = $arguments[
'image'];
120 $treatIdAsReference = $arguments[
'treatIdAsReference'];
121 $cropString = $arguments[
'crop'];
122 $absolute = $arguments[
'absolute'];
124 if (($src ===
null && $image ===
null) || ($src !==
null && $image !==
null)) {
125 throw new Exception(
'You must either specify a string src or a File object.', 1460976233);
130 $image = $imageService->getImage($src, $image, $treatIdAsReference);
132 if ($cropString ===
null && $image->hasProperty(
'crop') && $image->getProperty(
'crop')) {
133 $cropString = $image->getProperty(
'crop');
137 $cropVariant = $arguments[
'cropVariant'] ?:
'default';
138 $cropArea = $cropVariantCollection->getCropArea($cropVariant);
139 $processingInstructions = [
140 'width' => $arguments[
'width'],
141 'height' => $arguments[
'height'],
142 'minWidth' => $arguments[
'minWidth'],
143 'minHeight' => $arguments[
'minHeight'],
144 'maxWidth' => $arguments[
'maxWidth'],
145 'maxHeight' => $arguments[
'maxHeight'],
146 'crop' => $cropArea->isEmpty() ? null : $cropArea->makeAbsoluteBasedOnFile($image),
149 $processedImage = $imageService->applyProcessingInstructions($image, $processingInstructions);
150 return $imageService->getImageUri($processedImage, $absolute);
153 throw new Exception($e->getMessage(), 1509741907, $e);
154 }
catch (\UnexpectedValueException $e) {
156 throw new Exception($e->getMessage(), 1509741908, $e);
157 }
catch (\RuntimeException $e) {
159 throw new Exception($e->getMessage(), 1509741909, $e);
160 }
catch (\InvalidArgumentException $e) {
162 throw new Exception($e->getMessage(), 1509741910, $e);
174 $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
175 return $objectManager->get(ImageService::class);