本文整理汇总了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;
}