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


PHP ImageHelper::calculateMissingDimension方法代码示例

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


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

示例1: _normalizeDimensions

	/**
	 * Normalizes the given dimensions.  If width or height is set to 'AUTO', we calculate the missing dimension.
	 *
	 * @param int|string $width
	 * @param int|string $height
	 *
	 * @throws Exception
	 */
	private function _normalizeDimensions(&$width, &$height = null)
	{
		if (preg_match('/^(?P<width>[0-9]+|AUTO)x(?P<height>[0-9]+|AUTO)/', $width, $matches))
		{
			$width  = $matches['width']  != 'AUTO' ? $matches['width']  : null;
			$height = $matches['height'] != 'AUTO' ? $matches['height'] : null;
		}

		if (!$height || !$width)
		{
			list($width, $height) = ImageHelper::calculateMissingDimension($width, $height, $this->getWidth(), $this->getHeight());
		}
	}
开发者ID:harish94,项目名称:Craft-Release,代码行数:21,代码来源:Image.php

示例2: _getDimension

 /**
  * Return a dimension of the image.
  *
  * @param $dimension 'height' or 'width'
  * @param $transform
  *
  * @return null|float|mixed
  */
 private function _getDimension($dimension, $transform)
 {
     if ($this->kind != 'image') {
         return null;
     }
     if ($transform === null && isset($this->_transform)) {
         $transform = $this->_transform;
     }
     if (!$transform) {
         return parent::getAttribute($dimension);
     }
     $transform = craft()->assetTransforms->normalizeTransform($transform);
     $dimensions = array('width' => $transform->width, 'height' => $transform->height);
     if (!$transform->width || !$transform->height) {
         // Fill in the blank
         $dimensionArray = ImageHelper::calculateMissingDimension($dimensions['width'], $dimensions['height'], $this->_getWidth(), $this->_getHeight());
         $dimensions['width'] = (int) $dimensionArray[0];
         $dimensions['height'] = (int) $dimensionArray[1];
     }
     // Special case for 'fit' since that's the only one whose dimensions vary from the transform dimensions
     if ($transform->mode == 'fit') {
         $factor = max($this->_getWidth() / $dimensions['width'], $this->_getHeight() / $dimensions['height']);
         $dimensions['width'] = (int) round($this->_getWidth() / $factor);
         $dimensions['height'] = (int) round($this->_getHeight() / $factor);
     }
     return $dimensions[$dimension];
 }
开发者ID:amite,项目名称:arc-va,代码行数:35,代码来源:AssetFileModel.php

示例3: _resizeImage

 private function _resizeImage(&$image, $width, $height)
 {
     // Calculate the missing width/height for the asset - ensure aspect ratio is maintained
     $dimensions = ImageHelper::calculateMissingDimension($width, $height, $image->getWidth(), $image->getHeight());
     $image->resize($dimensions[0], $dimensions[1]);
 }
开发者ID:kcolls,项目名称:ImageResizer,代码行数:6,代码来源:ImageResizerService.php


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