• Модуль: faceid
  • Путь к файлу: ~/bitrix/modules/faceid/lib/api/face.php
  • Класс: BitrixFaceIdApiFace
  • Вызов: Face::validatePhoto
static function validatePhoto(&$photo)
{
	$photo = str_replace('data:image/jpeg', 'data://image/jpeg', $photo);
	$photo = base64_decode(str_replace('data://image/jpeg;base64,', '', $photo));

	if (!empty($photo))
	{
		// check image format
		$imageMeta = getimagesizefromstring($photo);
		if ($imageMeta !== false)
		{
			$format = $imageMeta[2];

			if ($format === IMAGETYPE_JPEG)
			{
				// check image size
				$width = $imageMeta[0];
				$height = $imageMeta[1];

				if ($width < 80 || $height < 80)
				{
					throw new ArgumentException('Minimum photo should be 80x80px');
				}
			}
			else
			{
				throw new ArgumentException('Unknown photo format, should be jpeg');
			}
		}
		else
		{
			throw new ArgumentException('Unknown photo format, should be jpeg encoded with base64');
		}
	}
	else
	{
		throw new ArgumentException('Unknown photo format, should be jpeg encoded with base64');
	}
}