08.10.05

Creating dynamic sigs for phpbb

Posted in General at 1:52 pm by jw

Creating dynamic sigs for phpbb is rather difficult, mainly due to the fun “security” features in phpbb.  First of all, for obvious reasons, it doesn’t let you include server side scripting within your sig text.  That rules out most efforts to create dynamic text, which leaves you with the use of a dynami image.  The problem with that is that phpbb is all nazi when parsing [img] tags and prevents you from using anything for an image other than something ending in .gif, .jpg or .png.  Well, there’s an easy solution – create a directory on your web server called “sig.png” and mess with the index.php file for that directory.  Phpbb (how do you capitalize that at the start of a sentence?) accepts it because it thinks it is looking at an image (the URL ends in .png) but in reality it’s hitting the index.php script for the directory.  Fun times!

In my case, for a first pass I just wanted the latest blog title to show up in the image I created, so the script ended up looking like this:

<?php

// Spit out headers
header(“Content-type: image/png”);
header(“Expires: “.gmdate(“D, d M Y H:i:s”, (time()+900)) . ” GMT”);

// Config Files
include (“../blog/wp-config.php”);

// Blog entry
$posts_list = wp_get_recent_posts(1);
foreach ($posts_list as $entry) {
  
 $choice = $entry[‘post_title’];
}

$choice = “Latest blog post: ” . $choice;

// Load a random quote
$font_name = “arial.ttf”;
$font_size = 9;

// Image Settings
$x_size = 400;
$y_size = 18;

// Calculate starting point of text (horizontal)
$line_width = imagettfbbox($font_size, 0, $font_name, $choice);
$x_start = 5;
$y_start = 13;
$max_width = $line_width[2];

// Create the image resource & assign colours.
$im = imagecreatetruecolor($x_size, $y_size);
$back = imagecolorallocate($im, 220, 220, 255);
imagefilledrectangle($im, 0, 0, $x_size-1, $y_size-1, $back);
$border = imagecolorallocate($im, 128, 128, 128);
imagerectangle($im, 0, 0, $x_size-1, $y_size-1, $border);

// Write the text on to the image.
$textcolor = imagecolorallocate($im, 0, 0, 0);
imagettftext($im, $font_size, 0, $x_start, $y_start, $textcolor, $font_name, $choice);

// Create and then destroy the image
imagepng($im);
@ImagePNG($im,$cache_filename) ;
imagedestroy($im);

?>

Will, it works.  I guess I’ll be putting some more stuff in there sometime in the future, but without the ability to create image maps, it’s probably going to be rather entertaining getting anything too useful in the script.  I guess my next avenue for playing is to see what web browsers do when the Content-Type header doesn’t match the apparent file extension.

Leave a Comment