255) { $speech = substr($speech,0,254); } list($avatar_width, $avatar_height, $avatar_type, $avatar_attr) = getimagesize($AVATAR) or die ("Can't load avatar image"); if ($avatar_type != 1 and $avatar_type != 3) { die("Avatar image isn't a GIF or PNG"); } $speechbubble_width = $FULL_WIDTH - 16; $speech_attrs = imageWordWrapBBox($speech, $speechbubble_width, $FONT_SIZE, $FONT_FACE); $speechbubble_height = $speech_attrs[2]; $full_height = $speechbubble_height + $avatar_height + 10; $text_y_start = abs(17 + (($speech_attrs[0] / 100) * 33)); $speech_im = imagecreate($FULL_WIDTH, $full_height); if ($avatar_type == 1) { $avatar_im = imagecreatefromgif("$AVATAR"); } else { $avatar_im = imagecreatefrompng("$AVATAR"); } $border_col['red'] = abs($SPEECHBUBBLE_COL['red'] / 5); $border_col['green'] = abs($SPEECHBUBBLE_COL['green'] / 5); $border_col['blue'] = abs($SPEECHBUBBLE_COL['blue'] / 5); $trans_col = imagecolorallocate($speech_im, 190, 190, 190); $bg_col = imagecolorallocate($speech_im, $SPEECHBUBBLE_COL['red'], $SPEECHBUBBLE_COL['green'], $SPEECHBUBBLE_COL['blue']); $text_col = imagecolorallocate($speech_im, $TEXT_COL['red'], $TEXT_COL['green'], $TEXT_COL['blue']); $bubble_border_col = imagecolorallocate($speech_im, $border_col['red'], $border_col['green'], $border_col['blue']); $stamp_text_col = imagecolorallocate($speech_im, $STAMP_TEXT_COL['red'], $STAMP_TEXT_COL['green'], $STAMP_TEXT_COL['blue']); imagefill($speech_im, 0, 0, $trans_col); $ORIENTATION == 'left' ? $stamp_x = $avatar_width + 1 : $stamp_x = 5; imagettftext($speech_im, $STAMP_FONT_SIZE, 0, $stamp_x, $full_height-($STAMP_FONT_SIZE + 5), $stamp_text_col, $FONT_FACE, $STAMP_TEXT); imagecolortransparent($speech_im,$trans_col); # Draw corners & joining lines imagearc($speech_im, 12, 12, 20, 20, 180, 275, $bubble_border_col); imagearc($speech_im, $speechbubble_width, 12, 20, 20, 275, 0, $bubble_border_col); imagearc($speech_im, $speechbubble_width, $speechbubble_height, 20, 20, 0, 90, $bubble_border_col); imagearc($speech_im, 12, $speechbubble_height, 20, 20, 90, 180, $bubble_border_col); imageline($speech_im, $speechbubble_width+10, 12, $speechbubble_width+10, $speechbubble_height, $bubble_border_col ); imageline($speech_im, 2, 12, 2, $speechbubble_height, $bubble_border_col ); imageline($speech_im, 12, 2, $speechbubble_width, 2, $bubble_border_col ); # Draw speech indicator $indicator_y_start = $speechbubble_height + 10; $indicator_circ = 60; if ($ORIENTATION == 'left') { imagearc($speech_im, $avatar_width + 5, $indicator_y_start, $indicator_circ, $indicator_circ, 0, 90, $bubble_border_col); imagearc($speech_im, $avatar_width + 5, $indicator_y_start, $indicator_circ + 40, $indicator_circ, 0, 90, $bubble_border_col); $join1 = $avatar_width + 35; $join2 = $avatar_width + 55; imageline($speech_im, 12, $speechbubble_height+10, $join1, $speechbubble_height+10, $bubble_border_col ); imageline($speech_im, $join2, $speechbubble_height+10, $speechbubble_width, $speechbubble_height+10, $bubble_border_col ); $avatar_x = 0; } else { imagearc($speech_im, ($FULL_WIDTH - $avatar_width) - 5, $indicator_y_start, $indicator_circ, $indicator_circ, 90, 180, $bubble_border_col); imagearc($speech_im, ($FULL_WIDTH - $avatar_width) - 5, $indicator_y_start, $indicator_circ + 30, $indicator_circ, 90, 180, $bubble_border_col); $join1 = ($FULL_WIDTH - $avatar_width) - 50; $join2 = ($FULL_WIDTH - $avatar_width) - 35; imageline($speech_im, 12, $speechbubble_height+10, $join1, $speechbubble_height+10, $bubble_border_col ); imageline($speech_im, $join2, $speechbubble_height+10, $speechbubble_width, $speechbubble_height+10, $bubble_border_col ); $avatar_x = $FULL_WIDTH - $avatar_width; } imagefill($speech_im, 30, 5, $bg_col); imagecopy($speech_im, $avatar_im, $avatar_x, $full_height-$avatar_height, 0,0, $avatar_width, $avatar_height); imageWordWrap($speech_im, $speech, $speechbubble_width, $text_col, 10,$text_y_start, $FONT_SIZE, $FONT_FACE); header ("Content-type: image/gif"); imagegif($speech_im); imagedestroy($speech_im); imagedestroy($avatar_im); ##### FUNCTIONS ## Code taken and modified (ever so slightly) from php.net function imageWordWrapBBox ( $Text, $Width = 400, $FontSize = 10, $Font ) { $Words = split ( ' ', $Text ); $Lines = array ( ); $Line = ''; foreach ( $Words as $Word ) { $Box = imagettfbbox ( $FontSize, 0, $Font, $Line . $Word ); $Size = $Box[4] - $Box[0]; if ( $Size > $Width ) { $Lines[] = trim ( $Line ); $Line = ''; } $Line .= $Word . ' '; } $Lines[] = trim ( $Line ); $Dimensions = imagettfbbox ( $FontSize, 0, $Font, 'AJLMYabdfghjklpqry019`@$^&*(,' ); $lineHeight = $Dimensions[1] - $Dimensions[5]; return array ( $lineHeight, $Lines, $lineHeight * count ( $Lines ) ); } function imageWordWrap ( $Image, $Text, $Width, $Color, $X = 0, $Y = 0, $FontSize = 10, $Font ) { $Data = imageWordWrapBBox ( $Text, $Width, $FontSize, $Font ); foreach ( $Data[1] as $Key => $Line ) { $locX = $X; $locY = $Y + ( $Key * $Data[0] ); imagettftext ( $Image, $FontSize, 0, $locX, $locY, $Color, $Font, $Line ); } return $Data; } ?>