<?php


abstract class phImaginator_Border extends phImaginator_Universal implements phImaginator_Module {

	protected static $runCollected = false;


	public static function outer($borderWidth, $color = '#000000') {
		$image_data =& parent::getCurrentResource();

		if (!is_array($color)) {
			$color = sscanf($color, '#%2x%2x%2x');
		}

		$newWidth = $image_data['width'] + 2 * $borderWidth;
		$newHeight = $image_data['height'] + 2 * $borderWidth;

		$borderedImage = imagecreatetruecolor($newWidth, $newHeight);
		imagealphablending($borderedImage, false);
		imagesavealpha($borderedImage, true);

		$colorResource = imagecolorallocate($borderedImage, $color[0], $color[1], $color[2]);
		imagefill($borderedImage, 0, 0, $colorResource);

		imagecopy($borderedImage, $image_data['resource'], $borderWidth, $borderWidth, 0, 0, $image_data['width'], $image_data['height']);

		$image_data['resource'] = $borderedImage;

		$image_data['width'] = imagesx($image_data['resource']);
		$image_data['height'] = imagesy($image_data['resource']);
	}


	public static function inner($borderWidth, $color = '#000000') {
		$image_data =& parent::getCurrentResource();

		if (!is_array($color)) {
			$color = sscanf($color, '#%2x%2x%2x');
		}

		$newWidth = $image_data['width'];
		$newHeight = $image_data['height'];

		$borderedImage = imagecreatetruecolor($newWidth, $newHeight);
		imagealphablending($borderedImage, false);
		imagesavealpha($borderedImage, true);

		$colorResource = imagecolorallocate($borderedImage, $color[0], $color[1], $color[2]);
		imagefill($borderedImage, 0, 0, $colorResource);

		imagecopy($borderedImage, $image_data['resource'], $borderWidth, $borderWidth, $borderWidth, $borderWidth, $image_data['width'] - 2 * $borderWidth, $image_data['height'] - 2 * $borderWidth);

		$image_data['resource'] = $borderedImage;
	}


	public static function stretched($borderWidth, $color = '#000000') {
		$image_data =& parent::getCurrentResource();

		if (!is_array($color)) {
			$color = sscanf($color, '#%2x%2x%2x');
		}

		$newWidth = $image_data['width'];
		$newHeight = $image_data['height'];

		$borderedImage = imagecreatetruecolor($newWidth, $newHeight);
		imagealphablending($borderedImage, false);
		imagesavealpha($borderedImage, true);

		$colorResource = imagecolorallocate($borderedImage, $color[0], $color[1], $color[2]);
		imagefill($borderedImage, 0, 0, $colorResource);

		imagecopyresampled($borderedImage, $image_data['resource'], $borderWidth, $borderWidth, 0, 0, $image_data['width'] - 2 * $borderWidth, $image_data['height'] - 2 * $borderWidth, $image_data['width'], $image_data['height']);

		$image_data['resource'] = $borderedImage;
	}
}







?>