Пример #1
0
		public function Rotate($angle){
			//always make the uncovered color transparent
			$rgba = Color::HexToRGBA("#FFFFFF", 0);
			$color = $this->AllocateColor($rgba[0]['r'], $rgba[0]['g'], $rgba[0]['b'], $rgba[0]['alpha']);
			
			$img = new Image();
			$img->handle = imagerotate($this->handle, $angle, $color);
			return $img;
		}
Пример #2
0
		public function Fill($color = '#000000', $alpha = 1){
			$rgba = Color::HexToRGBA($color, $alpha);
			if( imagefill($this->handle, 0, 0, $this->AllocateColor($rgba[0]['r'], $rgba[0]['g'], $rgba[0]['b'], $rgba[0]['alpha']) ) ){
				return true;
			}
			else{
				return false;
			}
		}
Пример #3
0
<?php
	set_include_path('.:backbone:global:jquery');
	
	require_once('Template.php');
	require_once('Color.php');
	require_once('Image.php');
	require_once('RedirectBrowserException.php');
	require_once('Session.php');
	require_once('URL.php');
	
	$tmpl = new Template();
	$tmpl->passedvar = "This string was passed through the Template object to be rendered in the HTML file.";
	
	$tmpl->hex = Color::RGBToHex(60, 120, 60);
	$tmpl->alpha = Color::HexToRGBA($tmpl->hex, .5);
	$tmpl->rgb = Color::HexToRGB($tmpl->hex);
	
	$img = new Image();
	$img->source = 'portrait.png';
	$img->Write->Normal(20, 20, "A Self Portrait of Me", 5, "#000000", 1);
	$img->destination = 'portrait2.png';
	$img->output();
	$img->clean();
	unset($img);
	
	//start a session and store a variable;
	setSession(0,'/'); // expires with browser session, the root is '/'
	setSessionVar('foo', 'bar'); //there's no retrieval function, so this is kind of stupid
	if( !isset($_SESSION['foo']) ){
		throw new RedirectBrowserException("example.php");
	}
Пример #4
0
		public function Font( $x, $y, $string, $textSize, $color, $angle, $font, $alpha = 1, $bg = "#000000", $bgA = 0, $padding = 0){
			$rgba = Color::HexToRGBA($color, $alpha);
			$bgrgba = Color::HexToRGBA($bg, $bgA);
			
			$size = imagettfbbox($textSize, 0, $font, $string);
			
			$text = new Image( (abs($size[2]) + abs($size[0])) + (2 * $padding), (abs($size[7]) + abs($size[1])) + (2 * $padding) );
			imagefill($text->handle, 0, 0, $this->AllocateColor($bgrgba[0]['r'], $bgrgba[0]['g'], $bgrgba[0]['b'], $bgrgba[0]['alpha']));
			
			imagealphablending($text->handle, true);
			$bool = imagettftext($text->handle, $textSize, 0, $padding, abs($size[5]) + $padding, $this->AllocateColor($rgba[0]['r'], $rgba[0]['g'], $rgba[0]['b'], $rgba[0]['alpha']), $font, $string);
			imagealphablending($text->handle, false);
			if( $bool ){
				$textRot = $text->Manipulate->Rotate($angle);
				if( $textRot ){
					//get dimensions
					$Ox = $textRot->width;
					$Oy = $textRot->height;
					$tx = $text->width;
					$ty = $text->width;
					
					//make angle safe
					$a = $angle;
					while( $a < 0 || $a >= 360 ){
						if( $a < 0 ){
							$a += 360;
						}
						
						if( $a >= 360 ){
							$a -= 360;
						}
					}
					
					$deltaX = 0;
					$deltaY = 0;
					
					//calculate re-anchor point based on quadrant
					if( $a >= 0 && $a <= 90 ){
						$deltaX = 0;
						$deltaY = -(sin(deg2rad($a)) * $tx);
					}
					elseif( $a > 90 && $a <= 180 ){
						$deltaX = -(sin(deg2rad(90 - (180 - $a))) * $tx);
						$deltaY = -$Oy;
					}
					elseif( $a > 180 && $a <= 270 ){
						$deltaX = -$Ox;
						$deltaY = -(sin(deg2rad(270 - $a)) * $ty);
					}
					elseif( $a > 270 && $a < 360 ){
						$deltaX = -(sin(deg2rad(360 - $a)) * $ty);
						$deltaY = 0;
					}
					
					//if the offset places the image outside of the original, crop until it fits
					//if cropped, reset the coordinate to 0
					$newx = $x + round($deltaX);
					$newy = $y + round($deltaY);
					
					$left = $newx < 0 ? abs($newx) : 0;
					$top = $newy < 0 ? abs($newy) : 0;
					
					$xp = $newx < 0 ? 0 : $newx;
					$yp = $newy < 0 ? 0 : $newy;

					$cropFit = $textRot->Manipulate->Crop($top, 0, 0, $left);
					
					if( $this->caller->Combine->Overlay( $cropFit, $xp, $yp, 0, 0, $cropFit->width, $cropFit->height ) ){
						return true;
					}
					else{
						return false;
					}
				}
				else{
					return false;
				}
			}
			else{
				return false;
			}
		}