<?php
// Electoral Vote Link Button (electoral-vote.com)
// (c) Donald Tetto http://donald.tetto.org/kerry/
// You'll need http://donald.tetto.org/kerry/digits.gif and http://donald.tetto.org/electoral.gif
$time=time();
if(
$time>@filemtime("current.png")+86400) {
  
$xml=@file_get_contents("http://dietrich.ganx4.com/president/server.php?rest");
  
$kerryvotes=substr($xml,strpos($xml,"<kerry>")+7,3);
  
$bushvotes=substr($xml,strpos($xml,"<bush>")+6,3);
  if(
strlen($kerryvotes)&&strlen($bushvotes)&&$kerryvotes>0&&$bushvotes>0) {
    
$image=imagecreatefromgif("electoral.gif");
    
$digits=imagecreatefromgif("digits.gif");
    
imagecolorset($digits,imagecolorexact($digits,0,0,0),255,255,255);
    
imagecopy($image,$digits,18,5,$kerryvotes[0]*6,0,6,6);
    
imagecopy($image,$digits,24,5,$kerryvotes[1]*6,0,6,6);
    
imagecopy($image,$digits,30,5,$kerryvotes[2]*6,0,6,6);
    
imagecopy($image,$digits,58,5,$bushvotes[0]*6,0,6,6);
    
imagecopy($image,$digits,64,5,$bushvotes[1]*6,0,6,6);
    
imagecopy($image,$digits,70,5,$bushvotes[2]*6,0,6,6);
    
imagepng($image,"current.png");
  }
}
header ("Content-type: image/png");
imagepng(imagecreatefrompng("current.png"));
?>