<?
    
require_once('nanofuncs.php');

    
$width 140;
    
$height 325;
    
$border 2;
    
$novelfile "/home/blob/nano/CaveatAstra.txt";
    
$title "Caveat Astra";
    
$title_color "#a5ce38";
    
$border_color "#ffffff";
    
$image "/var/www/html/images/nano2009.png";
    
$ttfont "/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf";
    
$fontsize 8;
    
$title_ttfont "/usr/share/fonts/truetype/ttf-bitstream-vera/VeraBI.ttf";
    
$title_fontsize 9;
    
$progress_color "#4dafef";
    
$background_color "#000000";
    
$icon_offset 8;
    
$progress_offset 4;
    
$progress_height 18;
    
$progress_thickness 1;
    
$goal_color "#a5ce38";

    
$maxx $width 1;
    
$maxy $height 1;
    switch ( 
strtolower(substr($imagestrlen($image) - 33)) ) {
        case 
'peg':
        case 
'jpg':
            
$icon imagecreatefromjpeg($image);
            break;
        case 
'png':
            
$icon imagecreatefrompng($image);
            break;
        case 
'gif':
        default:
            
$icon imagecreatefromgif($image);
            break;
    }

    
$im imagecreatetruecolor($width$height);

    
$c splitcolor($background_color);
    
$bc imagecolorallocate($im$c["r"], $c["g"], $c["b"]);

    
$c splitcolor($border_color);
    
$fc imagecolorallocate($im$c["r"], $c["g"], $c["b"]);

    
$c splitcolor($title_color);
    
$tc imagecolorallocate($im$c["r"], $c["g"], $c["b"]);

    
$c splitcolor($progress_color);
    
$pc imagecolorallocate($im$c["r"], $c["g"], $c["b"]);

    
$c splitcolor($goal_color);
    
$gc imagecolorallocate($im$c["r"], $c["g"], $c["b"]);

    
imagefill($im00$bc);

    if ( 
$border ) {
        
box($im00$maxx$maxy$border$fc);
    }

    if ( 
$icon ) {
        
$maxw $width $border $border $icon_offset $icon_offset;
        
$maxh $height $border $border $icon_offset $icon_offset;

        
$iw imagesx($icon);
        
$ih imagesy($icon);

        if ( 
$iw $maxw || $ih $maxh ) {
            
$xscale $maxw $iw;
            
$yscale $maxh $ih;
            
$scale = ( $xscale $yscale $yscale $xscale );
            
imagecopyresized($im$icon$border $icon_offset,
                
$border $icon_offset00,
                
$iw $scale$ih $scale$iw$ih);
        } else {
            
imagecopy($im$icon, ($maxw $iw)/$border $icon_offset,
                
$border $icon_offset00$iw$ih);
        }
    }

    
$x1 $border $progress_offset;
    
$x2 $maxx $border $progress_offset;
    
$y2 $maxy $border;

    if ( 
intval(Date("m")) == 11 ) {
        
$day intval(Date("d"));
        
$goal intval(round(50000 $day 30), 0);

        
$goaltext sprintf("Day %d Goal: %s"$daynumber_format($goal,0));

        
$textbox imagettfbbox($fontsize0$ttfont$goaltext);

        
$tw $textbox[2] - $textbox[0];
        
$th $textbox[1] - $textbox[7];

        
$y2 $y2 $progress_offset $th;

        
imagettftext($im$fontsize0, ($x2 $x1 $tw)/$x1$y2 -
            (
$textbox[7] < 0?$textbox[7]:0), $gc$ttfont$goaltext);
    }

    
$wc exec("wc " escapeshellarg($novelfile) . " | sed " .
        
escapeshellarg('s/[\t ]\+/,/g'));
    
$wc split(","$wc);
    
$words intval($wc[2]);
    
$wordtext sprintf("%s / 50,000"number_format($words,0));

    
$textbox imagettfbbox($fontsize0$ttfont$wordtext);

    
$tw $textbox[2] - $textbox[0];
    
$th $textbox[1] - $textbox[7];

    
$y2 $y2 $progress_offset $th;

    
imagettftext($im$fontsize0, ($x2 $x1 $tw)/$x1$y2 -
        (
$textbox[7] < 0?$textbox[7]:0), $pc$ttfont$wordtext);

    if ( 
$title ) {
        
$textbox imagettfbbox($title_fontsize0$title_ttfont$title);

        
$tw $textbox[2] - $textbox[0];
        
$th $textbox[1] - $textbox[7];

        
$y2 $y2 $progress_offset $th;

        
imagettftext($im$title_fontsize0, ($x2 $x1 $tw)/$x1$y2 -
            (
$textbox[7] < 0?$textbox[7]:0), $tc$title_ttfont$title);
    }

    
$y2 $y2 $progress_offset;
    
$y1 $y2 $progress_height $progress_thickness $progress_thickness;

    
box($im$x1$y1$x2$y2$progress_thickness$pc);

    
$ppct = ($words 50000?50000:$words) / 50000;

    
$x1 $x1 $progress_offset;
    
$y1 $y1 $progress_offset;
    
$x2 $x1 round(($x2 $x1) * $ppct,0);
    
$y2 $y2 $progress_offset;

    
imagefilledrectangle($im$x1$y1$x2$y2$pc);

    if ( 
intval(Date("m")) == 11 ) {
        
$x2 $maxx $border $progress_offset $progress_offset;
        
$ppct $goal 50000;
        
$x2 $x1 round(($x2 $x1) * $ppct0);

        
$goalpip = ( $progress_offset $progress_offset );

        
imagefilledrectangle($im$x2$y1 $goalpip$x2$y2 $goalpip$gc);
    }

    
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    
header("Cache-Control: no-cache, must-revalidate");
    
header("Pragma: no-cache");
    
header('Content-type: image/png');
    
imagepng($im);
?>