$imgdata['nick_xmax'] && $i++ < 4 && $imgdata['nick_size'] > 6){ $imgdata['nick_size'] -= 2; $nickbox = imagettfbboxext($imgdata['nick_size'], 'resources/font/'.$imgitem[$imgdata['nick_font']], $user['nick']); } } //if the nick is still too big, lets truncate it $nickbox = imagettfbboxext($imgdata['nick_size'], 'resources/font/'.$imgitem[$imgdata['nick_font']], $user['nick']); $i=0; while($nickbox['width'] + $statustextbox['width'] > $imgdata['nick_xmax'] && $i++ < 128){ $truncated = true; $user['nick'] = substr($user['nick'], 0, strlen($user['nick'])-1); $nickbox = imagettfbboxext($imgdata['nick_size'], 'resources/font/'.$imgitem[$imgdata['nick_font']], $user['nick'].' ...'); } if ($truncated) $user['nick'] = $user['nick'] . ' ...'; unset($nickbox); unset($statustextbox); /////////////////////////////////////////////////////////// // Smiley codes /////////////////////////////////////////////////////////// $nickbasesize = imagettfbboxext($imgdata['nick_size'], 'resources/font/'.$imgitem[$imgdata['nick_font']], '|'); if ($nickbasesize['height'] < 19) $emotesize = $nickbasesize['height']; else $emotesize = 19; $spacer = ' '; $spacewidth = imagettfbboxext($imgdata['nick_size'], 'resources/font/'.$imgitem[$imgdata['nick_font']], $spacer); $i=0; while($spacewidth['width']*strlen($spacer) < $emotesize+2 && $i++ < 30) $spacer .= ' '; $emoteoffsetx = ceil(($spacewidth['width']*strlen($spacer)-$emotesize)/2); $emoteoffsety = ceil(($nickbasesize['height']-$emotesize)/2); $i=0; while ($i <= count($smileys_from)){ $pos = strpos($user['nick'], $smileys_from[$i]); if ($pos !== false){ $imgEmote = imagecreatefrompng('resources/emotes/' . $smileys_to[$i] . '.png'); $emoteposx = imagettfbboxext($imgdata['nick_size'], 'resources/font/'.$imgitem[$imgdata['nick_font']], substr($user['nick'], 0, $pos)); imagecopyresampled($main_image, $imgEmote, $emoteposx['width'] + $imgdata['nick_x'] + $emoteoffsetx, $imgdata['nick_y'] - $emotesize + $emoteoffsety, 0, 0, $emotesize, $emotesize, imagesx($imgEmote), imagesy($imgEmote)); $user['nick'] = str_replace_once($smileys_from[$i], $spacer, $user['nick']); imagedestroy($imgEmote); } else { $i++; } } /////////////////////////////////////////////////////////// // Write out the Display Name /////////////////////////////////////////////////////////// if($imgdata['nick_shadow']){ imagettftext($main_image, $imgdata['nick_size'], 0, $imgdata['nick_x']+1, $imgdata['nick_y']+1, imagecolorallocatehex($main_image, $imgdata['nick_shadow_colour']), 'resources/font/'.$imgitem[$imgdata['nick_font']], $user['nick']); } imagettftext($main_image, $imgdata['nick_size'], 0, $imgdata['nick_x'], $imgdata['nick_y'], imagecolorallocatehex($main_image, $imgdata['nick_colour']), 'resources/font/'.$imgitem[$imgdata['nick_font']], $user['nick']); } /////////////////////////////////////////////////////////////////////////////////////////// // Status Text /////////////////////////////////////////////////////////////////////////////////////////// if ($enable['statustext']){ if ($imgdata['statustext_trailnick'] && $enable['nick']){ $nickbox = imagettfbboxext($imgdata['nick_size'], 'resources/font/'.$imgitem[$imgdata['nick_font']], $user['nick']); $imgdata['statustext_x'] = $imgdata['nick_x'] + $nickbox['width']; unset($nickbox); $imgdata['statustext_y'] = $imgdata['nick_y']; $user['statustext'] = ' ('.$user['statustext'].')'; } if($imgdata['statustext_shadow']){ imagettftext($main_image, $imgdata['statustext_size'], 0, $imgdata['statustext_x']+1, $imgdata['statustext_y']+1, imagecolorallocatehex($main_image, $imgdata['statustext_shadow_colour']), 'resources/font/'.$imgitem[$imgdata['statustext_font']], $user['statustext']); } imagettftext($main_image, $imgdata['statustext_size'], 0, $imgdata['statustext_x'], $imgdata['statustext_y'], imagecolorallocatehex($main_image, $imgdata['statustext_colour']), 'resources/font/'.$imgitem[$imgdata['statustext_font']], $user['statustext']); } /////////////////////////////////////////////////////////////////////////////////////////// // Personal Status Message /////////////////////////////////////////////////////////////////////////////////////////// //psm_x, psm_y, psm_xmax, psm_font, psm_size, psm_colour, psm_mediacolour, psm_wrap, psm_music if($enable['psm']){ if ($user['psmmedia'] != 'None' && $user['statusnumber'] == 2){ $user['psm'] = ''; $user['psmmedia'] = 'None'; } $psmbox = imagettfbboxext($imgdata['psm_size'], 'resources/font/'.$imgitem[$imgdata['psm_font']], $user['psm']); if ($user['psmmedia'] == 'None'){ $psmcolourval = imagecolorallocatehex($main_image, $imgdata['psm_colour']); }else{ $psmcolourval = imagecolorallocatehex($main_image, $imgdata['psm_mediacolour']); switch ($user['psmmedia']){ case 'Music': $imgPSM = imagecreatefrompng('resources/icon/'.$imgitem[$imgdata['psm_music']]); break; case 'Office': $imgPSM = imagecreatefrompng('resources/icon/'.$imgitem[$imgdata['psm_office']]); break; case 'Games': $imgPSM = imagecreatefrompng('resources/icon/'.$imgitem[$imgdata['psm_game']]); break; } $imagesx = imagesx($imgPSM); $imagesy = imagesy($imgPSM); $psm_y = ($psmbox[7] - $imagesy)/2 + $imgdata['psm_y']; imagecopy ($main_image, $imgPSM, $imgdata['psm_x'], $psm_y, 0, 0, $imagesx, $imagesy); $imgdata['psm_x'] = $imgdata['psm_x'] + $imagesx + 2; imagedestroy($imgPSM); } if($imgdata['psm_wrap']){ if ($psmbox['width'] > $imgdata['psm_xmax']){ $line1 = $user['psm']; $line1size = imagettfbboxext($imgdata['psm_size'], 'resources/font/'.$imgitem[$imgdata['psm_font']], $line1); $i=0; while($line1size['width'] > $imgdata['psm_xmax'] && $i++ < 128){ if(strstr($line1, ' ')) $line1 = substr($line1, 0, strrpos($line1, ' ')); else $line1 = substr($line1, 0, strlen($line1)-1); $line1size = imagettfbboxext($imgdata['psm_size'], 'resources/font/'.$imgitem[$imgdata['psm_font']], $line1); } $line2 = trim(substr($user['psm'], strlen($line1))); $line2size = imagettfbboxext($imgdata['psm_size'], 'resources/font/'.$imgitem[$imgdata['psm_font']], $line2); $i=0; if($line2size['width'] > $imgdata['psm_xmax']){ while($line2size['width'] > $imgdata['psm_xmax'] && $i++ < 128){ $line2 = substr($line2, 0, strlen($line2)-1); $line2size = imagettfbboxext($imgdata['psm_size'], 'resources/font/'.$imgitem[$imgdata['psm_font']], $line2.' ...'); } $line2 = $line2 . ' ...'; } if($imgdata['psm_shadow']){ imagettftext($main_image, $imgdata['psm_size'], 0, $imgdata['psm_x']+1, $imgdata['psm_y']+1 - floor(0.5*$psmbox['height']), imagecolorallocatehex($main_image, $imgdata['psm_shadow_colour']), 'resources/font/'.$imgitem[$imgdata['psm_font']], $line1); imagettftext($main_image, $imgdata['psm_size'], 0, $imgdata['psm_x']+1, $imgdata['psm_y']+1 + floor(0.6*$psmbox['height']), imagecolorallocatehex($main_image, $imgdata['psm_shadow_colour']), 'resources/font/'.$imgitem[$imgdata['psm_font']], $line2); } imagettftext($main_image, $imgdata['psm_size'], 0, $imgdata['psm_x'], $imgdata['psm_y'] - floor(0.5*$psmbox['height']), $psmcolourval, 'resources/font/'.$imgitem[$imgdata['psm_font']], $line1); imagettftext($main_image, $imgdata['psm_size'], 0, $imgdata['psm_x'], $imgdata['psm_y'] + floor(0.6*$psmbox['height']), $psmcolourval, 'resources/font/'.$imgitem[$imgdata['psm_font']], $line2); }else{ if($imgdata['psm_shadow']) imagettftext($main_image, $imgdata['psm_size'], 0, $imgdata['psm_x']+1, $imgdata['psm_y']+1, imagecolorallocatehex($main_image, $imgdata['psm_shadow_colour']), 'resources/font/'.$imgitem[$imgdata['psm_font']], $user['psm']); imagettftext($main_image, $imgdata['psm_size'], 0, $imgdata['psm_x'], $imgdata['psm_y'], $psmcolourval, 'resources/font/'.$imgitem[$imgdata['psm_font']], $user['psm']); } }else{ $psmbox = imagettfbboxext($imgdata['psm_size'], 'resources/font/'.$imgitem[$imgdata['psm_font']], $user['psm']); if($psmbox['width'] > $imgdata['psm_xmax']){ $i=0; while($psmbox['width'] > $imgdata['psm_xmax'] && $i++ < 128){ $user['psm'] = substr($user['psm'], 0, strlen($user['psm'])-1); $psmbox = imagettfbboxext($imgdata['psm_size'], 'resources/font/'.$imgitem[$imgdata['psm_font']], $user['psm'].' ...'); } $user['psm'] = $user['psm'] . ' ...'; } if($imgdata['psm_shadow']) imagettftext($main_image, $imgdata['psm_size'], 0, $imgdata['psm_x']+1, $imgdata['psm_y']+1, imagecolorallocatehex($main_image, $imgdata['psm_shadow_colour']), 'resources/font/'.$imgitem[$imgdata['psm_font']], $user['psm']); imagettftext($main_image, $imgdata['psm_size'], 0, $imgdata['psm_x'], $imgdata['psm_y'], $psmcolourval, 'resources/font/'.$imgitem[$imgdata['psm_font']], $user['psm']); } } /////////////////////////////////////////////////////////////////////////////////////////// // Last Update time /////////////////////////////////////////////////////////////////////////////////////////// if ($enable['time']){ $tsecs = strtotime($user['timestamp']); $tsecs = $tsecs + 3600 * $user['timezone']; $last_update = date ($imgdata['time_date'], $tsecs); if($imgdata['time_shadow']) imagettftext($main_image, $imgdata['time_size'], 0, $imgdata['time_x']+1, $imgdata['time_y']+1, imagecolorallocatehex($main_image, $imgdata['time_shadow_colour']), 'resources/font/'.$imgitem[$imgdata['time_font']], $imgdata['time_headstring'].$last_update.$imgdata['time_tailstring']); imagettftext($main_image, $imgdata['time_size'], 0, $imgdata['time_x'], $imgdata['time_y'], imagecolorallocatehex($main_image, $imgdata['time_colour']), 'resources/font/'.$imgitem[$imgdata['time_font']], $imgdata['time_headstring'].$last_update.$imgdata['time_tailstring']); } /////////////////////////////////////////////////////////////////////////////////////////// // Create and output the final image /////////////////////////////////////////////////////////////////////////////////////////// ob_start(); //output header information, and then the final image. header('Content-type: image/png'); Header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); Header("Expires: Sat, 01 Jan 2000 00:00:00 GMT"); Header("Pragma: no-cache"); $success = imagepng($main_image); $bin_main_image = ob_get_flush(); imagedestroy($main_image); if ($success = FALSE){ die('Error creating image'); }else{ $sql = 'UPDATE '.$database['prefix'].'image_config SET updated="'.$user['timestamp'].'" WHERE uid='.$uid.' AND iid='.$iid; mysql_query($sql); } $resFp = fopen($imgfile, "wb"); fwrite($resFp, $bin_main_image); fclose($resFp); }// end image cache }// end filetype png elseif ($filetype == 'txt'){ $sql = 'SELECT nick, psm, psmmedia, status, statusnumber FROM '.$database['prefix'].'users WHERE uid='.$uid; $sql_data = mysql_query($sql); header('Content-type: text/plain'); echo(mysql_result($sql_data, 0, 0)."\n"); echo(mysql_result($sql_data, 0, 1)."\n"); echo(mysql_result($sql_data, 0, 2)."\n"); echo(mysql_result($sql_data, 0, 3)."\n"); echo(mysql_result($sql_data, 0, 4)."\n"); }else{ echo('The filetype you have requested is not available to be displayed.'); } mysql_close(); /////////////////////////////////////////////////////////////////////////////////////////// // Functions /////////////////////////////////////////////////////////////////////////////////////////// //makes a thick line function imagethickline($img,$start_x,$start_y,$end_x,$end_y,$color,$thickness) { $angle=(atan2(($start_y - $end_y),($end_x - $start_x))); $dist_x=$thickness*(sin($angle)); $dist_y=$thickness*(cos($angle)); $p1x=ceil(($start_x + $dist_x)); $p1y=ceil(($start_y + $dist_y)); $p2x=ceil(($end_x + $dist_x)); $p2y=ceil(($end_y + $dist_y)); $p3x=ceil(($end_x - $dist_x)); $p3y=ceil(($end_y - $dist_y)); $p4x=ceil(($start_x - $dist_x)); $p4y=ceil(($start_y - $dist_y)); $array=array(0=>$p1x,$p1y,$p2x,$p2y,$p3x,$p3y,$p4x,$p4y); imagefilledpolygon ( $img, $array, (count($array)/2), $color ); } //see if a file exists at a url function url_exists($url){ if ($url != "") { if (@fopen($url,"r")){ return true; }else{ return false; } }else{ return false; } } //replace the first occurance of a string only function str_replace_once($search, $replace, $subject){ $pos = strpos($subject, $search); if ($pos > 0 || $pos===0){ return substr($subject, 0, $pos) . $replace . substr($subject, $pos+strlen($search)); } else { return $subject; } } //takes a hex colour value, and returns an array with decmal rgb values function imagecolorallocatehex($image, $color){ if ($color[0] == '#') $color = substr($color, 1); $int = hexdec($color); return ImageColorAllocate ($image, 0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int); } function imagettfbboxext($size, $fontfile, $text) { /*this function extends imagettfbbox and includes within the returned array the actual text width and height as well as the x and y coordinates the text should be drawn from to render correctly. This currently only works for an angle of zero and corrects the issue of hanging letters e.g. jpqg taken from http://mikeleigh.com/serendipity/index.php?/archives/20-php-function-imagettfbbox.html */ $bbox = imagettfbbox($size, 0, $fontfile, $text); //calculate x baseline if($bbox[0] >= -1) { $bbox['x'] = abs($bbox[0] + 1) * -1; } else { $bbox['x'] = abs($bbox[0] + 2); } //calculate actual text width $bbox['width'] = abs($bbox[2] - $bbox[0]); if($bbox[0] < -1) { $bbox['width'] = abs($bbox[2]) + abs($bbox[0]) - 1; } //caculate y baseline $bbox['y'] = abs($bbox[5] + 1); //calculate actaul text height $bbox['height'] = abs($bbox[7]) - abs($bbox[1]); if($bbox[3] > 0) { $bbox['height'] = abs($bbox[7] - $bbox[1]) - 1; } return $bbox; } function unicodedecode($str){ //Decodes unicode characters encoded in URL format, and standard URl encoding //eg. %20 is a space, %u0123 is a unicode character $res = ''; $i = 0; $max = strlen($str) - 6; while ($i <= $max){ $character = $str[$i]; if ($character == '%' && $str[$i + 1] == 'u'){ $value = hexdec(substr($str, $i + 2, 4)); $i += 6; if ($value < 0x0080) // 1 byte: 0xxxxxxx $character = chr($value); else if ($value < 0x0800) // 2 bytes: 110xxxxx 10xxxxxx $character = chr((($value & 0x07c0) >> 6) | 0xc0) . chr(($value & 0x3f) | 0x80); else // 3 bytes: 1110xxxx 10xxxxxx 10xxxxxx $character = chr((($value & 0xf000) >> 12) | 0xe0) . chr((($value & 0x0fc0) >> 6) | 0x80) . chr(($value & 0x3f) | 0x80); }else $i++; $res .= $character; } return urldecode($res . substr($str, $i)); } ?>