• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
  • This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

Signature Badge Script

Erik

Well-known member
#2
Eric, I see you got inspired by my signature :D
Ah, but mine is special. Like my post and refresh the page. :D

Edit: 10/21/2010: this post no longer makes sense because I no longer have the like counter in my signature. Originally, I had an image in my signature that displayed the number of likes I had, which refreshed on each pageview. So if you liked the post and refreshed the page, you would see the like count updated.
 

Erik

Well-known member
#7
give us the script!!! :D
Or make it dynamic so that we can plugin our details to the image URL (like username or ID) :)
If I hosted this it would probably bring my shared hosting account to its knees pretty quickly. :D (I do have a VPS, but it's not ready for a production environment). Feel free to host it yourself though:

EDIT: Oh, should probably mention requirements: PHP 5.0.0 or greater for SimpleXML support, GD, and the ability to use cURL. If the font size looks weird you probably have a different version of GD so you may need to adjust the font size (try 35). :)

PHP:
<?php
// XenForo signature generator by Erik Swan :)

function getPage($url){
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL, $url);
    curl_setopt($ch,CURLOPT_FRESH_CONNECT,TRUE);
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,5);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
    curl_setopt($ch, CURLOPT_USERAGENT, 'XenForo Signature Generator by Eriksrocks');
    curl_setopt($ch,CURLOPT_TIMEOUT,10);
    $html=curl_exec($ch);
    if($html==false){
      $m=curl_error(($ch));
      error_log($m);
    }
    curl_close($ch);
    return $html;
}

$username   = 'eriksrocks';
$userid     = '103';

$page = getPage('http://xenforo.com/community/members/' . $username . '.' . $userid . '/mini-stats.xml');
$xml = simplexml_load_string($page);
$likes = $xml->total_likes;
$trophies = $xml->trophy_points;

// DEFINE STUFF
$font = 'square.ttf';
$size = 27;
$x1 = 45;
$x2 = 136;
$y = 43;
$width = 198;
$height = 76;
$kerning = 3;

// DRAW

$final = imagecreatefrompng("sigbackground.png");
$black = imagecolorallocate($final, 0, 0, 0);

imagealphablending($final, true); // setting alpha blending on
imagesavealpha($final, true); // save alphablending setting (important)

$array = str_split($likes);
$hpos = $x1;

for($i=0; $i<count($array); $i++)
{
    $bbox = imagettftext( $final, $size, 0, $hpos, $y, $black, $font, $array[$i] );
    $hpos = intval($bbox[2])+$kerning;
}

$array = str_split($trophies);
$hpos = $x2;

for($i=0; $i<count($array); $i++)
{
    $bbox = imagettftext( $final, $size, 0, $hpos, $y, $black, $font, $array[$i] );
    $hpos = intval($bbox[2])+$kerning;
}

// OUTPUT

header('Content-type: image/png');
imagepng($final);
imagedestroy($final);
?>
Here is the image you need:
http://www.erikswan.net/sigbackground.png
You'll have to get the XenForo font yourself, sorry. :)

Enjoy! :D
 

Kier

XenForo Developer
Staff member
#8

Lawrence

Well-known member
#10
sweet XML stuff.. should be the next Have you seen? forum feature to cover :)
Actually, having the options to select certain elements to be displayed in ones signature is a pretty good idea. Admins can set which elements are allowed, and users can select from those. ie: trophies, likes.
 

Erik

Well-known member
#17
How do I embed the code into my sig?
Oh, sorry, we probably should have explained it better. The XML is only XML - you have to use the script I posted above (hosted on your own server). The script fetches the XML and then uses the image library GD to make an image out of it. :)

Then all you do is add an image tag in your signature pointed to the script on your server. :)
 

Disjunto

Well-known member
#19
Oh, sorry, we probably should have explained it better. The XML is only XML - you have to use the script I posted above (hosted on your own server). The script fetches the XML and then uses the image library GD to make an image out of it. :)

Then all you do is add an image tag in your signature pointed to the script on your server. :)

yup... that works, and takes in an id ;) now to make it look good :D
 

Erik

Well-known member
#20

yup... that works, and takes in an id ;) now to make it look good :D
I have a version that takes an ID too, but I didn't want to post it here for fear of the "OMG that is so cool I'm putting that in MY sig now!" kind of effect. And then my server would look like this:


Keep in mind anytime the image is displayed, anywhere, by anyone, a request is being made to the server and it has to create an image. So, as more people start adding images to their signatures, the requests start multiplying very quickly. :)

However, I'm actually considering turning this into a free hosted service where you can customize colors, designs, what you want displayed, etc. And it will have at least minimal caching. :) Development time! :D