<?
class ImageTemplateView extends Slot{

	function __construct($pquery) {
		$this->Slot($pquery);
		$width = 100;
		if(!isset($pquery['LocalTarget'][4]) || !preg_match('~color(\d)+~', $pquery['LocalTarget'][4])) $pquery['LocalTarget'][4] = 'color1';
		//printArray($pquery['LocalTarget']);
		if(isset($pquery['LocalTarget'][2]))
			if(preg_match('~^\d+$~', $pquery['LocalTarget'][2]))
				$width = $pquery['LocalTarget'][2];
		$height = 100;
		if(isset($pquery['LocalTarget'][3]))
			if(preg_match('~^\d+$~', $pquery['LocalTarget'][3]))
				$height = $pquery['LocalTarget'][3];
		$text = 'Text';
		if(isset($pquery['LocalTarget'][0]))
			if(preg_match('~^[\w(%20)\-]+$~', $pquery['LocalTarget'][0])){
				$text=ereg_replace('%20', ' ', $pquery['LocalTarget'][0]);
				$text=ereg_replace(' +', ' ', $pquery['LocalTarget'][0]);
			}
		$lenX = strlen($text) * 10;
		if($lenX + 20 >= $width) $posX = 0;
		else $posX = $width / 2 - $lenX / 2;
		//$srcImage = ImageCreateFromGIF('/js/tinymce/jscripts/tiny_mce/plugins/template/images/template.gif');
		$img = imagecreate($width - 5, $height - 5);
		switch($pquery['LocalTarget'][4]) {
			case 'color3':
				$background_color = imagecolorallocate($img, 255, 192, 203);//imagecolorallocate($img, 236, 206, 206);
				break;
			case 'color2':
				$background_color = imagecolorallocate($img, 255, 249, 156);
				break;
			case 'color1': default:
				$background_color = imagecolorallocate($img, 193, 249, 156);
				break;
		}
		$text_color = imagecolorallocate($img, 50, 30, 200);
		//imagecopy ($img, $srcImage, $posX-25,$height/2-20, 0 , 0 , 25, 32) ;
		imagestring($img, 5, $posX, $height / 2 - 10, $text, $text_color);
		imagepng($img);
		imagedestroy($img);
		exit;
	}
}
?>