- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/Service/Display/ClientSummary.php
- Класс: Bitrix\Crm\Service\Display\ClientSummary
- Вызов: ClientSummary::renderPhoto
private function renderPhoto(): string
{
$entityDependantIcon =
$this->entityTypeId === \CCrmOwnerType::Company
? 'ui-icon-common-company'
: 'ui-icon-common-user';
$style = '';
if ($this->photoFileId)
{
$fileData = \CFile::GetFileArray($this->photoFileId);
$originalWidth = $fileData['WIDTH'];
$originalHeight = $fileData['HEIGHT'];
$resizeWidth = static::DEFAULT_PHOTO_SIZE;
$resizeHeight = static::DEFAULT_PHOTO_SIZE;
$needResizeByShortestDimension = true;
$ratio = $originalHeight > 0 ? ($originalWidth / $originalHeight) : 0;
if ($ratio > 2 || $ratio < 0.5)
{
$needResizeByShortestDimension = false;
}
if ($needResizeByShortestDimension && $originalWidth > $originalHeight)
{
$resizeHeight = static::DEFAULT_PHOTO_SIZE;
$resizeWidth = $originalWidth * static::DEFAULT_PHOTO_SIZE / $originalHeight;
}
elseif ($needResizeByShortestDimension && $originalHeight > $originalWidth)
{
$resizeHeight = $originalHeight * static::DEFAULT_PHOTO_SIZE / $originalWidth;
$resizeWidth = static::DEFAULT_PHOTO_SIZE;
}
$resizedFile = \CFile::ResizeImageGet(
$this->photoFileId,
[
'width' => $resizeWidth,
'height' => $resizeHeight,
],
BX_RESIZE_IMAGE_PROPORTIONAL,
true,
false,
true
);
if ($resizedFile)
{
$styles = [];
if ($needResizeByShortestDimension)
{
$styles[] = 'background-image: url(\'' . Uri::urnEncode(htmlspecialcharsbx($resizedFile['src'])) . '\')';
}
else
{
$backgroundFile = \CFile::ResizeImageGet(
$this->photoFileId,
[
'width' => 1,
'height' => 1,
],
BX_RESIZE_IMAGE_EXACT,
true,
false,
true
);
$styles[] = 'background-image: url(\'' . Uri::urnEncode(htmlspecialcharsbx($resizedFile['src'])) . '\'), url(\'' . Uri::urnEncode(htmlspecialcharsbx($backgroundFile['src'])) . '\')';
$styles[] = 'background-size: contain, cover';
}
$style = ' style="' . implode(';', $styles) . ';"';
}
}
return '
';
}