skyhawk suggested this dynamic signature using some XML thing he just added to the forums that allows almost every page to be turned into XML, including the profile pages...
Anyway, I created this...I know it's incredibly dry, but I can't help it...I'm not exactly a graphics artist
Here's an example:

http://tibialottery.com/dic/217966.png is the image URL, the number is dynamic.
So incase you don't understand, here's Skyhawk's:

http://tibialottery.com/dic/34.png
(If either of them say there was an error it just means it didn't parse the XML correctly and you should probably reload the page.)
Anyway, tell me what you think!
OH! RIGHT! And you find the profile ID in the URL when you click on your name in the forums...
<Open-source-style>
<?php
date_default_timezone_set('America/Chicago');
class dicImager{
private $userID;
private $link = "http://www.dreamincode.net/forums/xml.php?showuser=%s";
private $userInformation = array();
private $ranks = array("Webmaster" => array("r" => 150, "g" => 20, "b" => 48), "Alumni" => array("r" => 239, "g" => 122, "b" => 200), "Mentor" => array("r" => 0, "g" => 183, "b" => 172), "Expert" => array("r" => 127, "g" => 73, "b" => 125), "Author" => array("r" => 164, "g" => 156, "b" => 110), "Contributor" => array("r" => 165, "g" => 108, "b" => 89), "Default" => array("r" => 0, "g" => 0, "b" => 0), "Admin" => array("r" => 39, "g" => 123, "b" => 89), "Moderator" => array("r" => 0, "g" => 0, "b" => 250));
private $height;
private $width;
public function __construct($id, $height = 100, $width = 330){
$this->userID = $id;
$this->setHeight($height);
$this->setWidth($width);
}
public function setHeight($height){
if(is_integer($height) && $height > 0){
$this->height = $height;
}else{
$this->height = 100;
}
}
public function setWidth($width){
if(is_integer($width) && $width > 0){
$this->width = $width;
}else{
$this->width = 330;
}
}
public function generateImage(){
Header('Content-type: image/png');
$image = imagecreatetruecolor($this->width, $this->height);
$black = imagecolorallocate($image, 0, 0, 0);
$white = imagecolorallocate($image, 255, 255, 255);
imagefilledrectangle($image, 1, 1, ($this->width-2), ($this->height-2), $white);
if(!$this->parseXML()){
imagestring($image, 5, 0, 50, "There was an error, sorry.", $black);
imagepng($image, null, 9);
}else{
$rank = $this->safelyGetRankColors();
$rank = imagecolorallocate($image, $rank['r'], $rank['g'], $rank['b']);
$dist_size = $this->getSafeSizes();
imagecopyresized($image, $this->getImageResource(), 1, 1, 0, 0, 100, 98, $dist_size['width'], $dist_size['height']);
imagestring($image, 3, 110, 5, "Name:", $black);
imagestring($image, 3, 148, 5, $this->userInformation['name'], $rank);
imagestring($image, 3, 110, 20, "Posts: ".$this->userInformation['posts'], $black);
imagestring($image, 3, 110, 35, "Reputation: ".$this->userInformation['rep'], $black);
imagestring($image, 3, 110, 50, "Gender: ".$this->userInformation['gender'], $black);
imagestring($image, 3, 110, 65, "Date joined: ".$this->userInformation['joined'], $black);
imagestring($image, 3, 110, 80, "Group: ", $black);
imagestring($image, 3, 155, 80, $this->userInformation['group'], $rank);
imagepng($image, NULL, 9);
imagedestroy($image);
}
}
private function getSafeSizes(){
$sizes = getimagesize($this->userInformation['image']);
$sizes = array("width" => $sizes[0], "height" => $sizes[1]);
return $sizes;
}
private function getImageResource(){
$userImage = $this->userInformation['image'];
$format = explode(".", $userImage);
$format = $format[count($format)-1];
if($format == "jpg" || $format == "jpeg"){
return imagecreatefromjpeg($userImage);
}else if($format == "png"){
return imagecreatefrompng($userImage);
}else if($format == "bmp"){
return imagecreatefromwbmp($userImage);
}else{
die("Error. Unknown file type. FORMAT: ".$format);
}
}
private function safelyGetRankColors(){
if(stristr($this->userInformation['group'], " w/DIC++") !== false){
$group = explode(" w/DIC++", $this->userInformation['group']);
$group = $group[0];
}else{
$group = $this->userInformation['group'];
}
if(strtolower(substr($group, -1)) == "s"){
$group = substr($group, 0, -1);
}
if(isset($this->ranks[$group])){
return $this->ranks[$group];
}else{
$this->ranks['Default'];
}
}
private function parseXML(){
libxml_use_internal_errors(true);
$filename = sprintf($this->link, $this->userID);
if(!$xml = simplexml_load_file($filename)){
for($i = 0; $i < 5 && $xml == false; $i++){
$xml = simplexml_load_file($filename); //Retry 5 tmes before giving up
}
if(!$xml){
return false;
}
}
libxml_use_internal_errors(false);
$info = $xml->xpath('profile');
$this->userInformation['name'] = (string) $info[0]->name;
$this->userInformation['gender'] = (string) $info[0]->gender->gender->value;
$this->userInformation['rep'] = (string) $info[0]->reputation;
$this->userInformation['posts'] = (string) $info[0]->posts;
$this->userInformation['joined'] = date('F jS, Y', strtotime((string) $info[0]->joined));
$this->userInformation['group'] = (string) $info[0]->group->span;
$this->userInformation['image'] = (string) $info[0]->photo;
return true;
}
}
function fixArrayReturnInteger($array, $key){
if(isset($array[$key])){
return (int) $array[$key];
}else{
return 0;
}
}
if(isset($_GET['id'])){
$width = fixArrayReturnInteger($_GET, "width");
$height = fixArrayReturnInteger($_GET, "height");
$dic = new dicImager($_GET['id'], $height, $width);
$dic->generateImage();
}else{
print "You need to add an ID to it! Like so:<br />\n<a href=\"http://tibialottery.com/dic/34.png\">http://tibialottery.com/dic/34.png</a><br />\nThe ID goes where the 34 is!";
}
?>
Last updated: May 29th, 2010 (10:41 PM Central US/Canada Time)
-- Made it retry 5 times before giving up...
-- Added Moderators, made it remove "s" from end of groups because of inconsistency
-- Made mentors "more blue"
-- Let images be resized via built-in parameters, like so:

http://tibialottery..../34h110w500.png
The above sets the image height to 110 and width to 500. (I became too addicted to the GD library, please stop me...)
Have suggestions/ideas for the code? Tell me about them too!
Yours,
Shane~
This post has been edited by ShaneK: 31 May 2010 - 09:02 AM

New Topic/Question
Reply




MultiQuote







|