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


PHP ImageHelper::getPngImageInfo方法代码示例

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


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

示例1: _getSaveOptions

	/**
	 * Get save options.
	 *
	 * @param int|null $quality
	 * @param string   $extension
	 * @return array
	 */
	private function _getSaveOptions($quality = null, $extension = null)
	{
		// Because it's possible for someone to set the quality to 0.
		$quality = ($quality === null || $quality === false ? $this->_quality : $quality);
		$extension = (!$extension ? $this->getExtension() : $extension);

		switch ($extension)
		{
			case 'jpeg':
			case 'jpg':
			{
				return array('jpeg_quality' => $quality, 'flatten' => true);
			}

			case 'gif':
			{
				$options = array('animated' => $this->_isAnimatedGif);

				if ($this->_isAnimatedGif)
				{
					// Imagine library does not provide this value and arbitrarily divides it by 10, when assigning,
					// so we have to improvise a little
					$options['animated.delay'] = $this->_image->getImagick()->getImageDelay() * 10;
				}

				return $options;
			}

			case 'png':
			{
				// Valid PNG quality settings are 0-9, so normalize and flip, because we're talking about compression
				// levels, not quality, like jpg and gif.
				$normalizedQuality = round(($quality * 9) / 100);
				$normalizedQuality = 9 - $normalizedQuality;

				if ($normalizedQuality < 0)
				{
					$normalizedQuality = 0;
				}

				if ($normalizedQuality > 9)
				{
					$normalizedQuality = 9;
				}

				$options = array('png_compression_level' => $normalizedQuality, 'flatten' => false);
				$pngInfo = ImageHelper::getPngImageInfo($this->_imageSourcePath);

				// Even though a 2 channel PNG is valid (Grayscale with alpha channel), Imagick doesn't recognize it as
				// a valid format: http://www.imagemagick.org/script/formats.php
				// So 2 channel PNGs get converted to 4 channel.

				if (is_array($pngInfo) && isset($pngInfo['channels']) && $pngInfo['channels'] !== 2)
				{
					$format = 'png'.(8 * $pngInfo['channels']);
				}
				else
				{
					$format = 'png32';
				}

				$options['png_format'] = $format;

				return $options;
			}

			default:
			{
				return array();
			}
		}
	}
开发者ID:harish94,项目名称:Craft-Release,代码行数:79,代码来源:Image.php

示例2: _getSaveOptions

 /**
  * Get save options.
  *
  * @param int|null $quality
  * @param string   $extension
  * @return array
  */
 private function _getSaveOptions($quality = null, $extension = null)
 {
     // Because it's possible for someone to set the quality to 0.
     $quality = $quality === null || $quality === false ? $this->_quality : $quality;
     $extension = !$extension ? $this->getExtension() : $extension;
     switch ($extension) {
         case 'jpeg':
         case 'jpg':
             return array('jpeg_quality' => $quality, 'flatten' => true);
         case 'gif':
             $options = array('animated' => $this->_isAnimatedGif);
             return $options;
         case 'png':
             // Valid PNG quality settings are 0-9, so normalize and flip, because we're talking about compression
             // levels, not quality, like jpg and gif.
             $normalizedQuality = round($quality * 9 / 100);
             $normalizedQuality = 9 - $normalizedQuality;
             if ($normalizedQuality < 0) {
                 $normalizedQuality = 0;
             }
             if ($normalizedQuality > 9) {
                 $normalizedQuality = 9;
             }
             $options = array('png_compression_level' => $normalizedQuality, 'flatten' => false);
             $pngInfo = ImageHelper::getPngImageInfo($this->_imageSourcePath);
             // Even though a 2 channel PNG is valid (Grayscale with alpha channel), Imagick doesn't recognize it as
             // a valid format: http://www.imagemagick.org/script/formats.php
             // So 2 channel PNGs get converted to 4 channel.
             if (is_array($pngInfo) && isset($pngInfo['channels']) && $pngInfo['channels'] !== 2) {
                 $format = 'png' . 8 * $pngInfo['channels'];
             } else {
                 $format = 'png32';
             }
             $options['png_format'] = $format;
             return $options;
         default:
             return array();
     }
 }
开发者ID:codeforamerica,项目名称:oakland-beta,代码行数:46,代码来源:Image.php


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