$row['money']) $min_value = $row['money']; if($max_value == "NaN" or $max_value < $row['money']) $max_value = $row['money']; if($cnt == 0) $first = $ts . ":00:00"; $last = $ts . ":00:00"; $data[$ts] = $row['money']; $d_money = $row['money'] - $o_money; $d_backers = $row['backers'] - $o_backers; $o_money = $row['money']; $o_backers = $row['backers']; $cnt++; } $last_max_value = $max_value; foreach ($goals as $goal) { if($goal > $max_value) $max_value = $goal; } # print "
"; print_r($data); print "
"; $total_w = 890; $total_h = 400; $days = 35; $font = "/home/ruinedkingdoms/public_html/wasteland2/Verdana.ttf"; $font_size = 8; $round_nearest = 200000; $x_border = 30; $y_border = 20; $h = $total_h - $y_border; $w = $total_w - $x_border; #print "Size: $w $h"; $image = imagecreate($w, $h); $colors['black'] = imagecolorallocatealpha($image, 0,0,0,0); $colors['white'] = imagecolorallocatealpha($image, 255,255,255,0); $colors['red'] = imagecolorallocatealpha($image, 255,0,0,0); $colors['green'] = imagecolorallocatealpha($image, 0,255,0,0); $colors['blue'] = imagecolorallocatealpha($image, 0,0,255,0); $colors['grey'] = imagecolorallocatealpha($image, 204,204,204,0); imagefilledrectangle($image, 0, 0, $w-1, $h-1, $colors['white']); $x_pixel = ceil(($days)*24 / ($w)); $min = floor($min_value/$round_nearest)*$round_nearest; $max = ceil($max_value/$round_nearest)*$round_nearest; $y_pixel = ($max - $min) / ($h); $time = strtotime($first); $last_time = strtotime($last); $lines = ($max - $min)/$round_nearest; #print "lines $lines $min $max"; for($i = 0; $i <= $lines; $i++) { $y = $h/$lines*$i; imageline($image, 0, $y, $w, $y, $colors['grey']); imageline($image, 0, $y, 4, $y, $colors['black']); imageline($image, $w, $y, $w-5, $y, $colors['black']); } foreach ($goals as $v1) { $y1 = convertValueToY($y_pixel, $min, $h, $v1); imageline($image, 1, $y1, $w-1, $y1, $colors['red']); } $x = 0; $o_date = $o_y1 = $o_y2 = $y2 = $v2 = ""; #print "$last $last_time $first $time

"; #$last_time = $time + $days*3600*24; $now = time(); while($last_time - $time >= 0) { $key = date('Y-m-d H', $time); $d = explode(" ", $key); $date = $d[0]; if($o_date == "") $o_date = $date; $v1 = $data[$key]; $y1 = convertValueToY($y_pixel, $min, $h, $v1); if($o_y1 == "") $o_y1 = $y1; if($v1 == 0) $y1 = $o_y1; $x++; if($date != $o_date) { imageline($image,$x,0,$x,$h, $colors['grey']); imageline($image,$x,$h,$x,$h-5, $colors['black']); $date_lines[$date] = $x; } if($key == "2012-03-17 09") imageline($image, $x-1, 1, $x-1, $h-1, $colors['green']); if($time <= $now) imageline($image, $x-1, $o_y1, $x, $y1, $colors['blue']); #print "$time $now $key v=$v1 y=$y1 $y_pixel min=$min max=$max h=$h $time $last_time $x_pixel
"; $time += 60*60; $o_date = $date; $o_y1 = $y1; } #die; imagerectangle($image, 0, 0, $w-1, $h-1, $colors['black']); $f_w = $w+$x_border*2; $f_h = $h+$y_border*2; $f_image = imagecreate($f_w, $f_h); $f_colors['black'] = imagecolorallocatealpha($f_image, 0,0,0,0); $f_colors['white'] = imagecolorallocatealpha($f_image, 255,255,255,0); $f_colors['red'] = imagecolorallocatealpha($f_image, 255,0,0,0); $f_colors['green'] = imagecolorallocatealpha($f_image, 0,255,0,0); $f_colors['blue'] = imagecolorallocatealpha($f_image, 0,0,255,0); $f_colors['grey'] = imagecolorallocatealpha($f_image, 204,204,204,0); imagefilledrectangle($f_image, 0, 0, $f_w, $f_h, $f_colors['white']); imagecopymerge($f_image, $image, $x_border, $y_border, 0, 0, $w, $h, 100); imageline($f_image, $x_border+2, $f_h-$y_border, $x_border+$w, $f_h-$y_border, $f_colors['grey']); imageline($f_image, $x_border+$w, $y_border+2, $x_border+$w, $y_border+$h, $f_colors['grey']); for($i = 0; $i <= $lines; $i++) { $y = $h/$lines * $i; if($round_nearest >= 1) { $lval = sprintf("%2.1fM", ($max - $round_nearest*$i)/1000000); $rval = sprintf("%-2.1fM", ($max - $round_nearest*$i)/1000000); } else { $lval = $rval = sprintf("%4.1f", ($max - $round_nearest*$i)); } imagettftext($f_image, $font_size, 0, 4, $y_border+$y+4, $f_colors['black'], $font, $lval); imagettftext($f_image, $font_size, 0, $f_w-$x_border+2, $y_border+$y+4, $f_colors['black'], $font, $rval); } #$font_size -= 2; $d = "13"; $len = strlen($d) * $font_size; $m_x = ($x_pixel*24 - $len)/2; imagettftext($f_image, $font_size, 0, $x_border+$m_x, $f_h - 5 , $f_colors['black'], $font, $d); foreach ($date_lines as $date => $x) { $d = date("d", strtotime($date)); #print "$mins_pixels $days_pixel $date $d $x
"; $len = strlen($d) * $font_size; $m_x = ($x_pixel*24 - $len)/2; #$m_x=0; imagettftext($f_image, $font_size, 0, $x+$x_border+$m_x, $f_h - 5 , $f_colors['black'], $font, $d); } $title = "Wasteland 2 Kickstarter Progress"; imagettftext($f_image, $font_size, 0, $x_border+2, $y_border-5, $f_colors['red'], $font, $title); $m_x = strlen($title) * $font_size; $m_x -= 50; $money = number_format($last_max_value); $delta = "+$" . number_format($d_money) . " and +" . number_format($d_backers) . " backers between " . date('H:00', strtotime($last)-3600) . " and " . date("H:00", strtotime($last)); imagettftext($f_image, $font_size, 0, $x_border+2 + $m_x + 2, $y_border-5, $f_colors['blue'], $font, "Updated: $last EDT (GMT-4) \$$money [$delta]"); #die; header("Content-Type: image/png"); imagepng($f_image); function convertValueToY($y_pixel, $min, $h, $value) { $value -= $min; $value /= $y_pixel; $value = $h-$value; return $value; } ?>