Image Based Flair
I have created an implementation of flair which generates an image of your current reputation automatically. It is currently using PHP GD.
Current Features
Configurable
Edit your accounts by opening system/config.yaml and editing the values.
Customizable
Create your own themes by editing/adding YAML files. (2 themes by default [basic,advanced] in 2 different flavors [normal, inverted])
Expandable
Currently supports all 4 SO sites. Adapts to new additions to the StackOverflow family with a simple config file.
Examples
This script no longer works due to the new flair API. I have no intention of updating it.
The desktop theme included in the distribution will not render exactly the same as the above. The reason is that I didn't include one font used due to licensing restrictions. For reference, the reputation font (missing) is DIN 1451 Engschrift LT. The theme files are as in, so by dropping in the font as dinb.ttf in the system/fonts folder, it should render as the above.
Changelog
Version 2.1 - 2009-08-03:
- Fixed
imageantialias()error on packaged versions ofphp-gd. - Renamed and reorganized themes.
- Added light-bg version of the SO logos.
Version 2.0 - 2009-07-31:
- Complete rewrite. The theme engine is now extremely flexible and allows the creation of complex themes. I've added one as an example.
Version 1.2 - 2009-07-25:
- Added "service" mode. To use, make sure
idis set tofalseinsystem/config.yaml, then specify the ID before the theme:/1/basic/StackOverflow.png.
Version 1.1 - 2009-07-25:
- Fixed
displayparameter being ignored for some objects - Fixed bug where a
badges.icons.sizevalue 0 or lower made the generation fail.
Installation
You need PHP 5.2.3 or greater, php_gd, and allow_fopen_url = 1 for this script to work. Make sure to make system/cache writable (an .htaccess file protects the directory from outside reads).
Combining Images
Kyle Cronin asked if I could provide an example on how to combine the images. You can use the following script to do so:
<?php
// If you have PHP 5.3 and the timezone isn't set properly.
date_default_timezone_set (@date_default_timezone_get());
require_once ('system/classes/spyc.php');
require_once ('system/classes/Image.php');
$theme = 'advanced';
header ('Expires: ' . date('r', time() + 300));
$flair_config = Spyc::YAMLLoad('system/config.yaml');
$domain = 'http://mydomain.com/flair/';
$width = 0;
$height = 0;
$padding = 10;
$images = array();
foreach($flair_config as $site => $data) {
$images[$site] = new Image();
$images[$site]->open($domain . $theme . '/' . $site . '.png');
$width += $padding + $images[$site]->width();
$height = max($height, $images[$site]->height());
}
$width -= $padding;
$img = new Image();
$img->new_transparent($width, $height);
$img->set_fill_color('#000');
$img->fill();
$offset = 0;
foreach($images as $image) {
$img->paste($image, $offset, 0);
$offset += $image->width() + $padding;
}
$img->output(IMG_PNG);
?>