Skip to content

Commit a7481f4

Browse files
authored
Merge pull request #72 from Idleworks/feature/image-cropvariant
Feature/image cropvariant
2 parents 70dc561 + 61c0bb7 commit a7481f4

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Classes/Annotation/Serializer/Type/Image.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,18 @@ class Image implements TypeInterface
3131
* @var mixed
3232
*/
3333
public $maxHeight;
34+
35+
/**
36+
* @var string
37+
*/
38+
public $cropVariant;
3439

3540
/**
3641
* @return array
3742
*/
3843
public function getParams(): array
3944
{
40-
return [$this->width, $this->height, $this->maxWidth, $this->maxHeight];
45+
return [$this->width, $this->height, $this->maxWidth, $this->maxHeight, $this->cropVariant];
4146
}
4247

4348
/**

Classes/Serializer/Handler/ImageHandler.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,22 @@ protected function processSingleImage($fileReference, array $type, Serialization
7878
$fileResource = $fileReference->getOriginalResource();
7979
}
8080

81+
if ($fileResource->hasProperty('crop') && $fileResource->getProperty('crop')) {
82+
$cropString = $fileResource->getProperty('crop');
83+
}
84+
$cropVariantCollection = CropVariantCollection::create((string)$cropString);
85+
$cropVariant = $type['params'][4] ?: 'default';
86+
$cropArea = $cropVariantCollection->getCropArea($cropVariant);
87+
8188
$file = $fileResource->getOriginalFile();
8289
$processedFile = $file->process(ProcessedFile::CONTEXT_IMAGECROPSCALEMASK, [
8390
'width' => $type['params'][0] ?? '',
8491
'height' => $type['params'][1] ?? '',
8592
'maxWidth' => $type['params'][2] ?? '',
8693
'maxHeight' => $type['params'][3] ?? '',
94+
'crop' => $cropArea->isEmpty() ? null : $cropArea->makeAbsoluteBasedOnFile($fileResource),
8795
]);
88-
96+
8997
return $this->fileReferenceService->getUrlFromResource($processedFile, $context);
9098
}
9199
}

0 commit comments

Comments
 (0)