本文整理汇总了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());
}
}
示例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];
}
示例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]);
}