X-Git-Url: http://git.typo3.org/Packages/TYPO3.CMS.git/blobdiff_plain/121c9ca653e29f139f12105513ebb3140d6609f6..f4a73f2f10263b1a23d7b7a693bbf3adb6351fbc:/typo3/sysext/core/Classes/Imaging/ImageManipulation/Area.php?ds=sidebyside diff --git a/typo3/sysext/core/Classes/Imaging/ImageManipulation/Area.php b/typo3/sysext/core/Classes/Imaging/ImageManipulation/Area.php index e74af9bebec..54388dd5e5c 100644 --- a/typo3/sysext/core/Classes/Imaging/ImageManipulation/Area.php +++ b/typo3/sysext/core/Classes/Imaging/ImageManipulation/Area.php @@ -136,6 +136,27 @@ class Area ); } + /** + * @param Ratio $ratio + * @return Area + */ + public function applyRatioRestriction(Ratio $ratio): Area + { + if ($ratio->isFree()) { + return $this; + } + $expectedRatio = $ratio->getRatioValue(); + $newArea = clone $this; + if ($newArea->height * $expectedRatio > $newArea->width) { + $newArea->height = $newArea->width / $expectedRatio; + $newArea->y += ($this->height - $newArea->height) / 2; + } else { + $newArea->width = $newArea->height * $expectedRatio; + $newArea->x += ($this->width - $newArea->width) / 2; + } + return $newArea; + } + /** * @return bool */