get paid to paste

// Ratio cropping
$offsetX	= 0;
$offsetY	= 0;

if (isset($_GET['cropratio']))
{
	$cropRatio = explode(':', (string) $_GET['cropratio']);
	if (count($cropRatio) == 2)
	{
		$ratioComputed = $width / $height;
		$cropRatioComputed = (float) $cropRatio[0] / (float) $cropRatio[1];
		
		if ($ratioComputed < $cropRatioComputed)
		{ // Image is too tall so we will crop the top and bottom
			$origHeight = $height;
			$height = $width / $cropRatioComputed;
			$offsetY = ($origHeight - $height) / 2;
		}
		else if ($ratioComputed > $cropRatioComputed)
		{ // Image is too wide so we will crop off the left and right sides
			$origWidth = $width;
			$width = $height * $cropRatioComputed;
			$offsetX = ($origWidth - $width) / 2;
		}
	}
}

Pasted: Jul 1, 2008, 9:27:57 pm
Views: 87