Entry 20 - dyn_info.php: Dynamic Image Placement for Counters, Etc.


dyn_info.php: Dynamic Image Placement for Counters, Etc.

This little script was an experimental foray into using images to replace available fonts; It is the long way 'round, but it looks pretty cool when you tweak it just so.

<?php
/*
Dynamic Date for hinkybox.com
written by Joshua Estell
hbadmin@gmail.com
*/
/* Variable Settings *******************/

$datestr = date("mdYw");
//$imgDayPrefix = "elements/gif/date/rg3_day_";
$imgPath= "/devpages/elem/alpha/";

$imgExt = ".gif";
//$banPrefix = "elements/gif/rg3_banner_";

/******************************/
// string output -->  01242004
// array construct
/*
$dateArray[0] = substr($datestr, 0,2);
$dateArray[1] = substr($datestr, 2,1);
$dateArray[2] = substr($datestr, 3,1);
$dateArray[3] = substr($datestr, 4,1);
$dateArray[4] = substr($datestr, 5,1);
$dateArray[5] = substr($datestr, 6,1);
$dateArray[6] = substr($datestr, 7,1);
$dateArray[7] = substr($datestr, 8,1);
"elements/gif/rg3_banner_";
/******************************/

function linuxUptime() {
  $ut = strtok( exec( "cat /proc/uptime" ), "." );
  $days = sprintf( "%02d", ($ut/(3600*24)) );
  $hours = sprintf( "%02d", ( ($ut % (3600*24)) / 3600) );
  $min = sprintf( "%02d", ($ut % (3600*24) % 3600)/60  );
  $sec = sprintf( "%02d", ($ut % (3600*24) % 3600)%60  );
  return array( $days, $hours, $min, $sec );

}
$ut = linuxUptime();
// If you would like to show the 
// seconds as well just add 
// [ , $ut[3] seconds ] after minutes.

//echo "$ut[0]$ut[1]$ut[2]$ut[3]"; 


$upTimeRaw = "$ut[0]$ut[1]$ut[2]$ut[3]";


// 04061249

$uTime[0] = substr($upTimeRaw, 0, 1);
$uTime[1] = substr($upTimeRaw, 1, 1);

$uTime[2] = substr($upTimeRaw, 2, 1);
$uTime[3] = substr($upTimeRaw, 3, 1);

$uTime[4] = substr($upTimeRaw, 4, 1);
$uTime[6] = substr($upTimeRaw, 5, 1);

$uTime[7] = substr($upTimeRaw, 6, 1);
$uTime[8] = substr($upTimeRaw, 7, 1);


//<!-- /* Server Load */ -->
$loadavg_array = explode(" ", exec("cat /proc/loadavg"));
$loadavg = $loadavg_array[2];

// print("Server load: " . $loadavg . "%");

// Linux server1.hinkybox.local 
// 2.4.22-1.2199.nptl #1 Wed Aug 
// 4 12:21:48 EDT 2004 i686 i686 i386 GNU/Linux

$uname_array = explode(" ", exec("uname -a"));

$platform = strtolower($uname_array[0]);
$hostname = strtolower($uname_array[1]);

$kernelver = strtolower($uname_array[2]);

//Display hostname 

 $nodeName = exec("uname -n"); 


$hostName[0] = substr($nodeName, 0, 1);
$hostName[1] = substr($nodeName, 1, 1);

$hostName[2] = substr($nodeName, 2, 1);
$hostName[3] = substr($nodeName, 3, 1);

$hostName[4] = substr($nodeName, 4, 1);
$hostName[5] = substr($nodeName, 5, 1);

$hostName[6] = substr($nodeName, 6, 1);
$hostName[7] = substr($nodeName, 7, 1);

$hostName[8] = substr($nodeName, 8, 1);
$hostName[9] = substr($nodeName, 9, 1);

$hostName[10] = substr($nodeName, 10, 1);
$hostName[11] = substr($nodeName, 11, 1);

$hostName[12] = substr($nodeName, 12, 1);
$hostName[13] = substr($nodeName, 13, 1);

$hostName[14] = substr($nodeName, 14, 1);
$hostName[15] = substr($nodeName, 15, 1);

$hostName[16] = substr($nodeName, 16, 1);
$hostName[17] = substr($nodeName, 17, 1);

$hostName[18] = substr($nodeName, 18, 1);
$hostName[19] = substr($nodeName, 19, 1);

$hostName[20] = substr($nodeName, 20, 1);
$hostName[21] = substr($nodeName, 21, 1);



// character translation

function getChar($char) {

global $imgPath;
global $imgExt;

switch($char) {

//--numbers------------------------------

  case "1";
     echo($imgPath."1".$imgExt);   break;
  case "2";
     echo($imgPath."2".$imgExt);   break;
  case "3";
     echo($imgPath."3".$imgExt);   break;
  case "4";
     echo($imgPath."4".$imgExt);   break;
  case "5";
     echo($imgPath."5".$imgExt);   break;
  case "6";
     echo($imgPath."6".$imgExt);   break;
  case "7";
     echo($imgPath."7".$imgExt);   break;
  case "8";
     echo($imgPath."8".$imgExt);   break;
  case "9";
     echo($imgPath."9".$imgExt);   break;
  case "0";
     echo($imgPath."0".$imgExt);   break;


//--letters------------------------------

  case "a";
     echo($imgPath."a".$imgExt);   break;
  case "b";
     echo($imgPath."b".$imgExt);   break;
  case "c";
     echo($imgPath."c".$imgExt);   break;
  case "d";
     echo($imgPath."d".$imgExt);   break;
  case "e";
     echo($imgPath."e".$imgExt);   break;
  case "f";
     echo($imgPath."f".$imgExt);   break;
  case "g";
     echo($imgPath."g".$imgExt);   break;
  case "h";
     echo($imgPath."h".$imgExt);   break;
  case "i";
     echo($imgPath."i".$imgExt);   break;
  case "j";
     echo($imgPath."j".$imgExt);   break;
  case "k";
     echo($imgPath."k".$imgExt);   break;
  case "l";
     echo($imgPath."l".$imgExt);   break;
  case "m";
     echo($imgPath."m".$imgExt);   break;
  case "n";
     echo($imgPath."n".$imgExt);   break;
  case "o";
     echo($imgPath."o".$imgExt);   break;
  case "p";
     echo($imgPath."p".$imgExt);   break;
  case "q";
     echo($imgPath."q".$imgExt);   break;
  case "r";
     echo($imgPath."r".$imgExt);   break;
  case "s";
     echo($imgPath."s".$imgExt);   break;
  case "t";
     echo($imgPath."t".$imgExt);   break;
  case "u";
     echo($imgPath."u".$imgExt);   break;
  case "v";
     echo($imgPath."v".$imgExt);   break;
  case "w";
     echo($imgPath."w".$imgExt);   break;
  case "x";
     echo($imgPath."x".$imgExt);   break;
  case "y";
     echo($imgPath."y".$imgExt);   break;
  case "z";
     echo($imgPath."z".$imgExt);   break;

//--chars----------------------------------
  case "+";
     echo($imgPath."+".$imgExt);   break;
  case "-";
     echo($imgPath."-".$imgExt);   break;
  case "!";
     echo($imgPath."!".$imgExt);   break;
  case "@";
     echo($imgPath."@".$imgExt);   break;
  case "#";
     echo($imgPath."#".$imgExt);   break;
  case "$";
     echo($imgPath."$".$imgExt);   break;
  case "%";
     echo($imgPath."percent".$imgExt);   break;
  case "^";
     echo($imgPath."^".$imgExt);   break;
  case "%";
     echo($imgPath."%".$imgExt);   break;
  case "^";
     echo($imgPath."^".$imgExt);   break;
  case "&";
     echo($imgPath."&".$imgExt);   break;
  case "*";
     echo($imgPath."ast".$imgExt);   break;
  case "(";
     echo($imgPath."(".$imgExt);   break;
  case ")";
     echo($imgPath.")".$imgExt);   break;
  case "'";
     echo($imgPath."par1".$imgExt);   break;
  case "\"";
     echo($imgPath."par2".$imgExt);   break;
  case ":";
     echo($imgPath."colon".$imgExt);   break;
  case ";";
     echo($imgPath."semi".$imgExt);   break;
  case ">";
     echo($imgPath."rang".$imgExt);   break;
  case "<";
     echo($imgPath."lang".$imgExt);   break;
  case ".";
     echo($imgPath."per".$imgExt);   break;
  case ",";
     echo($imgPath."comma".$imgExt);   break;
  case "/";
     echo($imgPath."fslash".$imgExt);   break;
  case "[";
     echo($imgPath."lbrak".$imgExt);   break;
  case "]";
     echo($imgPath."rbrak".$imgExt);   break;
  case "}";
     echo($imgPath."rbrace".$imgExt);   break;
  case "{";
     echo($imgPath."lbrace".$imgExt);   break;


default :
     echo($imgPath."dna".$imgExt);
 }
}

?>
<img src="<?= ($imgPath); ?>uptime.gif" height="7" />
<img src="<?= ($imgPath); ?>halfspace.gif" height="7" />
<img src="<?= getChar($uTime[4]); ?> height="7" />
<img src="<?= getChar($uTime[6]); ?> height="7" />

Weee! A couple of issues with whitespace between images, which makes the HTML into an illegible blob, but oh well, all in the name of science.

Perhaps a couple years until bandwith has a script like this working right. ◊

See it work
See the source (.phps)


1 Lonely Reader Missive


01 Dave Snotheer said on Wed Dec 31 23:00:01 EST

cool man I am stealing it

Comments are currently off for this entry.

Past Entries

Minutiae Today

Using the Blogger Data API
Reference Material: Bringing Wheatblog up to date with XML-RPC and the GData API: Authors will be able to post from their favorite Blogger-aware authoring tool.
Gmail: Help Center - What are the keyboard shortcuts?
Keyboard Shortcuts for Gmail. Delete those chain emails from your batty 2nd-cousin lightning-fast and with ease.
Free! Icons for your website or application at MaxPower
Nice little blog post about CC, GPL, LGPL and royalty-free, and what they mean. Also a nice bunch of links to GPL/Free icon sets.

EtCetera

Feedburner.
Save Me Some Gas Money.
(mt) Media Temple - Web Hosting Services