• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/File/Image/Engine.php
  • Класс: BitrixMainFileImageEngine
  • Вызов: Engine::getInfo
public function getInfo($flashEnabled = false)
{
	if($this->info !== null)
	{
		return $this->info;
	}

	if($this->file === null)
	{
		return null;
	}

	if(!file_exists($this->file))
	{
		return null;
	}

	/*
	This will protect us from scan the whole file in order to find out size of the xbm image
	ext/standard/image.c php_getimagetype
	*/
	$handler = fopen($this->file, "rb");
	if(!is_resource($handler))
	{
		return null;
	}
	$signature = fread($handler, 12);
	fclose($handler);

	if($flashEnabled)
	{
		$flashPattern = "
			|FWS                   # php_sig_swf
			|CWS                   # php_sig_swc
		";
	}
	else
	{
		$flashPattern = "";
	}

	if(preg_match("/^(
		GIF                    # php_sig_gif
		|\xff\xd8\xff       # php_sig_jpg
		|\x89\x50\x4e       # php_sig_png
		".$flashPattern."
		|8BPS                  # php_sig_psd
		|BM                    # php_sig_bmp
		|\xff\x4f\xff       # php_sig_jpc
		|II\x2a\x00          # php_sig_tif_ii
		|MM\x00\x2a          # php_sig_tif_mm
		|FORM                  # php_sig_iff
		|\x00\x00\x01\x00  # php_sig_ico
		|\x00\x00\x00\x0c
		\x6a\x50\x20\x20
		\x0d\x0a\x87\x0a   # php_sig_jp2
		|RIFF.{4}WEBP		   # php_sig_riff php_sig_webp
		)/xs",
		$signature
	))
	{
		//This function does not require the GD image library.
		$size = getimagesize($this->file);

		if($size !== false)
		{
			$this->info = ((new ImageInfo())
				->setWidth($size[0])
				->setHeight($size[1])
				->setFormat($size[2])
				->setMime($size["mime"])
			);
			return $this->info;
		}
	}

	return null;
}