/** * 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]; }
/** * Returns the actual height attribute, since $this->height gets routed to getHeight() now. * * @access private * @return mixed */ private function _getHeight() { return parent::getAttribute('height'); }