Location: PHPKode > scripts > Pictorus GIF Text > pictorus-gif-text/class.pGifText.php
<?
# CLASS FILE
# -------------------------------------------------------------------------------
#	Name:			Pictoru's Gif Title												
#	Author:			Ciprian Voicu												
#	Version: 		1.0 														
#	Date:			2006-08-29													
#	Description:	• creates and outputs gif images from ttf fonts, usefull for 
#					texts which are not supported  by the browsers
#	License: 		GNU GPL														
# -------------------------------------------------------------------------------

require_once("class.pGifTitle.config.php");
# class 
class pGifTitle {
	var $image;
	
	# destroy image resource
	function Destroy(){
		imagedestroy($this->image);
	}

	# output the images
	function Output(){
		header("Content-Type: image/gif");
		imagegif($this->image);
		$this->Destroy();
	}

	# returns the decimal values for the color
	function pDecColors($color){
		$color	=	str_replace("#", "", $color);
		$colors['red']	=	hexdec(substr($color, 0, 2));
		$colors['blue']	=	hexdec(substr($color, 2, 2));
		$colors['green']=	hexdec(substr($color, 4, 2));
		return $colors;
	}
	
	# make gif from a given text with a given font
	function Title($text, $font_id, $font_size="16", $font_color="FF0000", $bg_color="FFFFFF", $transparent=true){
		$fonts=unserialize(IMG_TTF_FONTS);
		$font=IMG_FONT_FOLDER.$fonts[$font_id];
		
		$text=stripslashes(rawurldecode($text));
			
		$dim		=	imagettfbbox($font_size, 0, $font, $text);
		$img_width	=	$dim[4]+1;
		$img_height	=	abs($dim[1])+abs($dim[7]);
			
		$text_colors=	$this->pDecColors($font_color);
		$bg_colors	=	$this->pDecColors($bg_color);
				
		$this->image= 	imagecreate($img_width, $img_height);
		$background	= 	imagecolorallocate($this->image, $bg_colors['red'], $bg_colors['blue'], $bg_colors['green']);
		$fcolor		= 	imagecolorallocate($this->image, $text_colors['red'], $text_colors['blue'], $text_colors['green']);
		
		imagettftext($this->image, $font_size, 0, 0, abs($dim[5]), $fcolor, $font, $text);
		if($transparent){
			imagecolortransparent($this->image, $background);
		}
		$this->Output();
	}
}
?>
Return current item: Pictorus GIF Text