2 declare(strict_types = 1);
84 $this->selectedRatio = current($this->allowedAspectRatios)->getId();
104 $config[
'title'] ??
'',
107 $config[
'selectedRatio'] ??
null,
111 }
catch (\Throwable $throwable) {
112 throw new InvalidConfigurationException(sprintf(
'Invalid type in configuration for crop variant: %s', $throwable->getMessage()), 1485278693, $throwable);
122 $allowedAspectRatiosAsArray = [];
123 foreach ($this->allowedAspectRatios as
$id => $allowedAspectRatio) {
124 $allowedAspectRatiosAsArray[
$id] = $allowedAspectRatio->asArray();
126 if ($this->coverAreas !==
null) {
127 $coverAreasAsArray = [];
128 foreach ($this->coverAreas as $coverArea) {
129 $coverAreasAsArray[] = $coverArea->asArray();
135 'cropArea' => $this->cropArea->asArray(),
136 'allowedAspectRatios' => $allowedAspectRatiosAsArray,
138 'focusArea' => $this->focusArea ? $this->focusArea->asArray() :
null,
139 'coverAreas' => $coverAreasAsArray ??
null,
146 public function getId(): string
173 if (!$this->selectedRatio) {
176 $newVariant = clone $this;
177 $newArea = $this->cropArea->makeAbsoluteBasedOnFile($file);
178 $newArea = $newArea->applyRatioRestriction($this->allowedAspectRatios[$this->selectedRatio]);
179 $newVariant->cropArea = $newArea->makeRelativeBasedOnFile($file);
189 $this->allowedAspectRatios = [];
190 foreach ($ratios as $ratio) {
201 if (isset($this->allowedAspectRatios[$ratio->getId()])) {
202 throw new InvalidConfigurationException(sprintf(
'Ratio with with duplicate ID (%s) is configured. Make sure all configured ratios have different ids.', $ratio->getId()), 1485274618);
204 $this->allowedAspectRatios[$ratio->getId()] = $ratio;
213 $this->coverAreas = [];
214 foreach ($areas as $area) {
225 $this->coverAreas[] = $area;