getKeepAspectRatio example



    private function assertConfig(
        MediaFolderEntity $folder,
        bool $useParentConfiguration,
        bool $createThumbnails,
        bool $keepAspectRatio,
        int $thumbnailQuality
    ): void {
        static::assertEquals($useParentConfiguration$folder->getUseParentConfiguration());
        static::assertEquals($createThumbnails$folder->getConfiguration()?->getCreateThumbnails());
        static::assertEquals($keepAspectRatio$folder->getConfiguration()?->getKeepAspectRatio());
        static::assertEquals($thumbnailQuality$folder->getConfiguration()?->getThumbnailQuality());
    }

    private function assertConfigIsSame(MediaFolderEntity $folder, MediaFolderEntity $childFolder): void
    {
        static::assertEquals($folder->getConfigurationId()$childFolder->getConfigurationId());
    }
}
/** * @param array{width: int, height: int} $imageSize * * @return array{width: int, height: int} */
    private function calculateThumbnailSize(
        array $imageSize,
        MediaThumbnailSizeEntity $preferredThumbnailSize,
        MediaFolderConfigurationEntity $config
    ): array {
        if (!$config->getKeepAspectRatio() || $preferredThumbnailSize->getWidth() !== $preferredThumbnailSize->getHeight()) {
            $calculatedWidth = $preferredThumbnailSize->getWidth();
            $calculatedHeight = $preferredThumbnailSize->getHeight();

            $useOriginalSizeInThumbnails = $imageSize['width'] < $calculatedWidth || $imageSize['height'] < $calculatedHeight;

            return $useOriginalSizeInThumbnails ? [
                'width' => $imageSize['width'],
                'height' => $imageSize['height'],
            ] : [
                'width' => $calculatedWidth,
                'height' => $calculatedHeight,
            ];
Home | Imprint | This part of the site doesn't use cookies.