font_dir)); //create the image $im = @imagecreatetruecolor($this->width, $this->height); //transparent background imagealphablending($im, false); imagesavealpha($im, true); $clear = imagecolorallocatealpha($im, 0, 0, 0, 127); imagefilledrectangle($im, 0, 0, $this->width-1, $this->height-1, $clear); //colour of text $text_color = imagecolorallocate($im, $this->red, $this->green, $this->blue); //lowercase $this->text = strtolower( $this->text ); //the first word needs to be bold //first word is in $words[0], the rest is in $words[1] $words = explode(' ', $this->text, 2); //if there's only one word in the title, create an empty second word if( !isset( $words[1] ) ) $words[1] = ''; //add the space back to the start of the second word $words[1] = ' '.$words[1]; //work out how wide the first word will be $font = 'Med'; $b = imagettfbbox( $this->font_size, 0, $font, $words[0] ); $firstWordWidth = $b[2] - $b[0]; $baseline = $this->height - $this->baseline_amt; //write first word $start_x = 0; if( $this->align == 'center' ) { //we want to align center, get the width of the entire text, based on thin font $allTextBB = imagettfbbox( $this->font_size, 0, 'Lite', $this->text ); $allTextWidth = $allTextBB[2] - $allTextBB[0]; $start_x = ($this->width - $allTextWidth - 20 )/2; } imagettftext($im, $this->font_size, 0, $start_x, $baseline, $text_color, $font, $words[0]); //write second word $font = 'Lite'; imagettftext($im, $this->font_size, 0, $start_x + $firstWordWidth, $baseline, $text_color, $font, $words[1]); //construct filename $filename = $this->filename( $this->text ); //output to file imagepng($im, $this->write_to.$filename); imagedestroy($im); } function filename( $text='' ) { if( empty($text) ) $text = $this->text; $text = strtolower( $text ); return ereg_replace( "[^A-Za-z0-9]", "", $text ).'.png'; } } //end class ?>