* The TYPO3 project - inspiring people to share!
*/
+use TYPO3\CMS\Core\Resource\FileInterface;
+
class CropVariant
{
/**
$this->cropArea = $cropArea;
if ($allowedAspectRatios) {
$this->setAllowedAspectRatios(...$allowedAspectRatios);
+ if ($selectedRatio && isset($this->allowedAspectRatios[$selectedRatio])) {
+ $this->selectedRatio = $selectedRatio;
+ } else {
+ $this->selectedRatio = current($this->allowedAspectRatios)->getId();
+ }
}
- $this->selectedRatio = $selectedRatio;
$this->focusArea = $focusArea;
if ($coverAreas !== null) {
$this->setCoverAreas(...$coverAreas);
return $this->focusArea;
}
+ /**
+ * @param FileInterface $file
+ * @return CropVariant
+ */
+ public function applyRatioRestrictionToSelectedCropArea(FileInterface $file): CropVariant
+ {
+ if (!$this->selectedRatio) {
+ return $this;
+ }
+ $newVariant = clone $this;
+ $newArea = $this->cropArea->makeAbsoluteBasedOnFile($file);
+ $newArea = $newArea->applyRatioRestriction($this->allowedAspectRatios[$this->selectedRatio]);
+ $newVariant->cropArea = $newArea->makeRelativeBasedOnFile($file);
+ return $newVariant;
+ }
+
/**
* @param Ratio[] $ratios
* @throws InvalidConfigurationException