<?php


abstract class phImaginator_Box extends phImaginator_Universal implements phImaginator_Module {

	protected static $runCollected = false;


	public static function fit($width, $height) {
		$image_data =& parent::getCurrentResource();

		$imageBox = imagecreatetruecolor($width, $height);
		imagealphablending($imageBox, false);
		imagesavealpha($imageBox, true);

		$proportions['w'] = $width / $image_data['width'];
		$proportions['h'] = $height / $image_data['height'];

		$use_proportion = max($proportions);

		$crop_width = $image_data['width'] * $use_proportion;
		$crop_height = $image_data['height'] * $use_proportion;

		imagecopyresampled(
			$imageBox,
			$image_data['resource'],
			0,
			0,
			($crop_width - $width) / $use_proportion / 2,
			($crop_height - $height) / $use_proportion / 2,
			$crop_width,
			$crop_height,
			$image_data['width'],
			$image_data['height']
		);

		$image_data['resource'] = $imageBox;
		$image_data['width'] = $width;
		$image_data['height'] = $height;
	}


	public static function crop($width, $height, $start_x, $start_y) {
		$image_data =& parent::getCurrentResource();

		$imageBox = imagecreatetruecolor($width, $height);
		imagealphablending($imageBox, false);
		imagesavealpha($imageBox, true);

		imagecopy(
			$imageBox,
			$image_data['resource'],
			0,
			0,
			$start_x,
			$start_y,
			$width,
			$height
		);

		$image_data['resource'] = $imageBox;
		$image_data['width'] = $width;
		$image_data['height'] = $height;
	}

}







?>