All pastes #740962 Raw Edit

Untitled

public text v1 · immutable
·published 2007-10-18 11:08 UTC
rendered paste body
<?php
header("Content-type: image/png");
if(filemtime("img.cache") < time() - 0)
{
$feed = trim(file_get_contents("http://ws.audioscrobbler.com/1.0/user/kud0s/recenttracks.txt"));

$line = split("\n", $feed);
$count = 0;
for ($i=0;isset($line[$i]) && $i < 6;$i++)
{
	$data = split(",", $line[$i]);
	if($data[0] > time()-86400)
	{
		$ago = time() - $data[0];
		$hours = floor($ago/60/60);
		$minutes = floor(($ago/60)%60);
		$date = (($hours > 0) ? $hours."h and ":'').$minutes."m ago\n";
	}
	else
	{
		$date = date("D M j G:i:s", (int)$data[0])."\n";
	}
	$dates .= $date;
	$track = str_replace(' ? ', " - ", utf8_decode($data[1]))."\n";
	$len = ($len > strlen($track.$date)) ? $len : strlen($track.$date);
	$tracks .= $track;
}


$im = @imagecreatetruecolor($len*5.5,$i*16)
	or die("Cannot Initialize new GD image stream");
	imagesavealpha($im, true);
$trans_colour = imagecolorallocatealpha($im, 0, 0, 0, 127);
imagefill($im, 0, 0, $trans_colour);
$text_color = imagecolorallocate($im, 50, 50, 50);
imagettftext ($im, 50, 0, ($len*5)-150, ($i*16)-3, imagecolorallocate($im, 254, 215, 215), "BastardusSans.ttf", "kudos");
imagettftext ($im, 8, 0, 5, 14, $text_color, "BastardusSans.ttf", $tracks);
imagettftext ($im, 8, 0, $len*3.7, 14, $text_color, "BastardusSans.ttf", $dates);
imagepng($im, "img.cache");
imagedestroy($im);

}
readfile("img.cache");
?>