当前位置: 首页>>代码示例>>PHP>>正文


PHP ImageHelper::parseSvgSize方法代码示例

本文整理汇总了PHP中ImageHelper::parseSvgSize方法的典型用法代码示例。如果您正苦于以下问题:PHP ImageHelper::parseSvgSize方法的具体用法?PHP ImageHelper::parseSvgSize怎么用?PHP ImageHelper::parseSvgSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ImageHelper的用法示例。


在下文中一共展示了ImageHelper::parseSvgSize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: loadImage

	/**
	 * Loads an image from a file system path.
	 *
	 * @param string $path
	 *
	 * @throws Exception
	 * @return Image
	 */
	public function loadImage($path)
	{
		if (!IOHelper::fileExists($path))
		{
			throw new Exception(Craft::t('No file exists at the path “{path}”', array('path' => $path)));
		}

		if (!craft()->images->checkMemoryForImage($path))
		{
			throw new Exception(Craft::t("Not enough memory available to perform this image operation."));
		}

		$extension = IOHelper::getExtension($path);

		if ($extension === 'svg')
		{
			if (!craft()->images->isImagick())
			{
				throw new Exception(Craft::t('The file “{path}” does not appear to be an image.', array('path' => $path)));
			}

			$svg = IOHelper::getFileContents($path);

			if ($this->minSvgWidth !== null && $this->minSvgHeight !== null)
			{
				// Does the <svg> node contain valid `width` and `height` attributes?
				list($width, $height) = ImageHelper::parseSvgSize($svg);

				if ($width !== null && $height !== null)
				{
					$scale = 1;

					if ($width < $this->minSvgWidth)
					{
						$scale = $this->minSvgWidth / $width;
					}

					if ($height < $this->minSvgHeight)
					{
						$scale = max($scale, ($this->minSvgHeight / $height));
					}

					$width = round($width * $scale);
					$height = round($height * $scale);

					$svg = preg_replace(ImageHelper::SVG_WIDTH_RE, "\${1}{$width}px\"", $svg);
					$svg = preg_replace(ImageHelper::SVG_HEIGHT_RE, "\${1}{$height}px\"", $svg);
				}
			}

			try
			{
				$this->_image = $this->_instance->load($svg);
			}
			catch (\Imagine\Exception\RuntimeException $e)
			{
				// Invalid SVG. Maybe it's missing its DTD?
				$svg = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'.$svg;
				$this->_image = $this->_instance->load($svg);
			}
		}
		else
		{
			$imageInfo = @getimagesize($path);

			if (!is_array($imageInfo))
			{
				throw new Exception(Craft::t('The file “{path}” does not appear to be an image.', array('path' => $path)));
			}

			$this->_image = $this->_instance->open($path);
		}

		$this->_extension = $extension;
		$this->_imageSourcePath = $path;

		if ($this->_extension == 'gif')
		{
			if (!craft()->images->isGd() && $this->_image->layers())
			{
				$this->_isAnimatedGif = true;
			}
		}

		return $this;
	}
开发者ID:harish94,项目名称:Craft-Release,代码行数:94,代码来源:Image.php


注:本文中的ImageHelper::parseSvgSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。