Alright, I wrote a little script for you kiddies to use, although I’m sure it could be optimized:
<?php
/*******************/
/*** Intructions ***/
/*******************/
/* Follow these simple instructions to get this working on your own
* server.
*
* 1) Place this file anywhere in your server, it doesn't matter in
* the slightest where you place it...
*
* 2) Change the $dir variable under the configuration header to be
* the path to where your images are located. This should be the
* absolute path from the root of the server.
*
* 3) OPTIONAL: If you use a different filename than 'phrases.txt'
* for your generated file phrases, put the filename in the
* $phrases variable under the configuration header. It should
* be loacted inside the $dir folder.
*
* 4) If you're going to use the file generation, then you must
* define a font file. It must be in TrueType format. It is
* easiest to get this from a friend using Windows if you can't
* find one on your Mac.
*
* You're done. Congratulations. Simply link to this file in your
* images.
*/
/*********************/
/*** Configuration ***/
/*********************/
// The directory in which your images and phrases.txt file are located
$dir = "/home/nokrev6/public_html/images/kirupa_footers/";
$phrases = "phrases.txt";
$font = "MyriadPro-Bold.otf";
$make_footer = rand ( 0, 2 );
if ( $make_footer == 0 && file_exists ( $font ) &&
file_exists ( $dir.$phrases ) ) { // Make footer
// Decide on Contents
$strings = explode ( "
", file_get_contents($dir.$phrases) );
$string = $strings[rand ( 1, count( $strings ) )-1];
$backgrounds = array (
array ( 77, 52, 55 ),
array ( 63, 82, 95 ),
array ( 79, 95, 63 )
);
$colors = array (
array ( 242, 222, 224 ),
array ( 199, 216, 227 ),
array ( 211, 234, 187 )
);
$pallet = rand(1,count($backgrounds))-1;
$bg = $backgrounds[$pallet];
$cl = $colors[$pallet];
// Create Image
$im = @imagecreate(300, 60);
$background_color = imagecolorallocate($im, $bg[0], $bg[1], $bg[2]);
$text_color = imagecolorallocate($im, $cl[0], $cl[1], $cl[2]);
imageantialias($im, 1);
if ( strlen ( $string ) > 25 ) {
imagettftext($im, 14, 0, 15, 35, $text_color, $font, $string);
} elseif ( strlen ( $string ) > 15 ) {
imagettftext($im, 20, 0, 15, 36, $text_color, $font, $string);
} else {
imagettftext($im, 28, 0, 15, 41, $text_color, $font, $string);
}
// Flush the output
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
} elseif ( $make_footer >= 1 ) { // Get existing footers
// Get Files
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
if ( $filename != $phrases ) {
$files[] = $filename;
}
}
sort($files);
// Remove . and ..
array_shift($files);
array_shift($files);
// Count and Randomize
$rand = rand(1, count($files))-1;
switch ( strstr($files[$rand],".") ) {
case ".jpg":
case ".jpeg":
header("Content-type: image/jpeg");
break;
case ".gif":
header("Content-type: image/gif");
break;
case ".png":
header("Content-type: image/png");
break;
}
include("../../images/kirupa_footers/".$files[$rand]);
}
?>
Update: It now supports jpg, jpeg, png, and gif.
Second Update: It now sends the headers correctly, and decreases the size on longer text.
Also, it always uses the same image on a page, due to your browser’s caching.