Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
PreviewImage.php
1<?php
2
4
7
9{
10 public static function getSize(FileInfo $fileInfo, PreviewImageOptions $options = null): Rectangle
11 {
12 $previewWidth = 0;
13 $previewHeight = 0;
14 if ($fileInfo->isImage())
15 {
16 // Sync with \Bitrix\UI\Controller\FileUploader::previewAction
17 $previewWidth = $options ? $options->getWidth() : 300;
18 $previewHeight = $options ? $options->getHeight() : 300;
19 $previewMode = $options ? $options->getMode() : Image::RESIZE_PROPORTIONAL;
20
21 $destinationRectangle = new Rectangle($previewWidth, $previewHeight);
22 $sourceRectangle = new Rectangle($fileInfo->getWidth(), $fileInfo->getHeight());
23 $needResize = $sourceRectangle->resize($destinationRectangle, $previewMode);
24 if ($needResize)
25 {
26 $previewWidth = $destinationRectangle->getWidth();
27 $previewHeight = $destinationRectangle->getHeight();
28 }
29 else
30 {
31 $previewWidth = $sourceRectangle->getWidth();
32 $previewHeight = $sourceRectangle->getHeight();
33 }
34 }
35
36 return new Rectangle($previewWidth, $previewHeight);
37 }
38}
const RESIZE_PROPORTIONAL
Definition Image.php:24
static getSize(FileInfo $fileInfo, PreviewImageOptions $options=null)