• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/classes/general/file.php
  • Класс: CFile
  • Вызов: CFile::ShowImage
static function ShowImage($strImage, $iMaxW=0, $iMaxH=0, $sParams=null, $strImageUrl="", $bPopup=false, $sPopupTitle=false, $iSizeWHTTP=0, $iSizeHHTTP=0, $strImageUrlTemplate="")
{
	if(is_array($strImage))
	{
		$arImgParams = $strImage;
		$iImageID = isset($arImgParams['ID']) ? (int)$arImgParams['ID'] : 0;
	}
	else
	{
		$arImgParams = static::_GetImgParams($strImage, $iSizeWHTTP, $iSizeHHTTP);
		$iImageID = (int)$strImage;
	}

	if(!$arImgParams)
	{
		return "";
	}

	$iMaxW = (int)$iMaxW;
	$iMaxH = (int)$iMaxH;
	$intWidth = (int)$arImgParams['WIDTH'];
	$intHeight = (int)$arImgParams['HEIGHT'];
	if(
		$iMaxW > 0
		&& $iMaxH > 0
		&& ($intWidth > $iMaxW || $intHeight > $iMaxH)
	)
	{
		$coeff = ($intWidth/$iMaxW > $intHeight/$iMaxH? $intWidth/$iMaxW : $intHeight/$iMaxH);
		$iHeight = (int)roundEx($intHeight/$coeff);
		$iWidth = (int)roundEx($intWidth/$coeff);
	}
	else
	{
		$coeff = 1;
		$iHeight = $intHeight;
		$iWidth = $intWidth;
	}

	$strImageUrlTemplate = strval($strImageUrlTemplate);
	if($strImageUrlTemplate === '' || $iImageID <= 0)
	{
		$strImage = $arImgParams['SRC'];
	}
	else
	{
		$strImage = CComponentEngine::MakePathFromTemplate($strImageUrlTemplate, array('file_id' => $iImageID));
	}

	$strImage = Uri::urnEncode($strImage);

	if(GetFileType($strImage) == "FLASH")
	{
		$strReturn = '
			
		';
	}
	else
	{
		$strAlt = $arImgParams['ALT'] ?? ($arImgParams['DESCRIPTION'] ?? '');

		if($sParams === null || $sParams === false)
		{
			$sParams = 'border="0" alt="'.htmlspecialcharsEx($strAlt).'"';
		}
		elseif(!preg_match('/(^|\s)alt\s*=\s*(["']?)(.*?)(\2)/is', $sParams))
		{
			$sParams .= ' alt="'.htmlspecialcharsEx($strAlt).'"';
		}

		if($coeff === 1 || !$bPopup)
		{
			$strReturn = '';
		}
		else
		{
			if($sPopupTitle === false)
			{
				$sPopupTitle = GetMessage('FILE_ENLARGE');
			}

			if($strImageUrl <> '')
			{
				$strReturn =
					''.
					''.
					'';
			}
			else
			{
				static::OutputJSImgShw();

				$strReturn =
					''.
						''.
					'';
			}
		}
	}

	return $bPopup? $strReturn : print_url($strImageUrl, $strReturn);
}