protected function calculateDimensions($originalWidth, $originalHeight)
	{
		// check if target size is set and valid
		if (empty($this->targetWidth) || ($this->targetWidth <= 0)) {
			throw new ImageProcessorException('Target width is not set or is invalid');
		}
		if (empty($this->targetHeight) || ($this->targetHeight <= 0)) {
			throw new ImageProcessorException('Target height is not set or is invalid');
		}

		$newDimensions = $this->getExpectedSize(false);
		
		$dimensions = array();
		
		// set default dimensions for image-to-image copy
		$dimensions['sourceLeft'] = null;
		$dimensions['sourceTop'] = null;
		$dimensions['sourceWidth'] = null;
		$dimensions['sourceHeight'] = null;
		
		$dimensions['destWidth'] = max(round($newDimensions['width']), 1);
		$dimensions['destHeight'] = max(round($newDimensions['height']), 1);

		// get ratios 
		$wRatio = max($originalWidth / $newDimensions['width'], 1);
		$hRatio = max($originalHeight / $newDimensions['height'], 1);

		if ( ! $this->cropMode) {
			$wRatio = $hRatio = max($wRatio, $hRatio);
		} else {
			$wRatio = $hRatio = min($wRatio, $hRatio);
		}

		// set source dimensions to center (with target aspect ratio)
		$sourceHeight = $newDimensions['height'] * $hRatio;
		$dimensions['sourceTop'] =
				round(($originalHeight - $sourceHeight) / 2);
		$dimensions['sourceHeight'] = round($sourceHeight);

		$sourceWidth = $newDimensions['width'] * $wRatio;
		$dimensions['sourceLeft'] =
				round(($originalWidth - $sourceWidth) / 2);
		$dimensions['sourceWidth'] = round($sourceWidth);

		return $dimensions;
	}