Post by pixeleater on Feb 7, 2009 2:35:02 GMT
Graphics guy turned casual coder here. I'm trying to do a basic Last.fm avatar generator. All of the free ones use ugly jpeg compression, so this will let me use png's. Someone showed me the php they use (theirs works), but so far it's loading blanks.
I chmod'd /media/ to 777, then put this .php, pixeleater.png, and /font/segoeui.ttf inside. What super basic thing am I overlooking? I don't see how pixeleater.png could be the bg and generate new images also named pixeleater.png.
I'm open to using any script, I just wish this would work.
<?php
if ($_GET['debug']) {
echo $_SERVER['HTTP_REFERER'];
exit();
}
header('cache-control: no-cache');
header('content-type: image/png');
//header('content-type: text/plain');
/*if (!preg_match('/^http:\/\/(www\.)?what.cd/', $_SERVER['HTTP_REFERER'])) {
$i = imagecreate(500,500);
imagecolourallocate($i, 255, 255, 255);
imagepng($i);
exit();
}*/
$bgs = array(
array(
'filename' => 'pixeleater.png', 'colour' => array(0xff,0xff,0xff), 'font' => 'http://pixeleater.net/media/fonts/segoeui.ttf', 'size' => 8,
'text' => array(
array('pretext' => 'LAST PLAYED:', 'posttext' => '', 'x' => 2, 'y' => 126, 'variant' => false),
array('pretext' => 'a: ', 'posttext' => '', 'x' => 5, 'y' => 138, 'variant' => 'artist'),
array('pretext' => 't: ', 'posttext' => '', 'x' => 5, 'y' => 145, 'variant' => 'name'),
),
'lines' => array(
array('start' => array('x' => 0, 'y' => 127), 'end' => array('x' => 93, 'y' => 127), 'colour' => array(0xdd, 0xdd, 0xdd)),
),
),
);
$bg = 0;
$scrobbles = @file_get_contents("http://ws.audioscrobbler.com/1.0/user/PixelEater/recenttracks.xml", false, stream_context_create(array('http' => array('timeout'=>2))));
if ($scrobbles === false) {
echo file_get_contents($bgs[$bg]['filename']);
exit();
}
$doc = new DOMDocument();
$doc->loadXML($scrobbles);
$tracks = $doc->getElementsByTagName("track");
$artist = $tracks->item(0)->getElementsByTagName("artist");
$artist = $artist->item(0)->textContent;
$name = $tracks->item(0)->getElementsByTagName("name");
$name = $name->item(0)->textContent;
/*$r = pg_query($db, "SELECT * FROM songs ORDER BY timestamp DESC LIMIT 1");
$r = pg_fetch_assoc($r);
$artist = $r['artist'];
$name = $r['title'];*/
$i = imagecreatefrompng($bgs[$bg]['filename']);
foreach($bgs[$bg]['lines'] as $line) {
$c = imagecolorallocate($i, $line['colour'][0], $line['colour'][1], $line['colour'][2]);
imageline($i, $line['start']['x'], $line['start']['y'], $line['end']['x'], $line['end']['y'], $c);
}
foreach($bgs[$bg]['text'] as $line) {
$c = imagecolorallocate($i, $bgs[$bg]['colour'][0], $bgs[$bg]['colour'][1], $bgs[$bg]['colour'][2]);
imagettftext($i, $bgs[$bg]['size'], 0, $line['x'], $line['y'], -$c, $bgs[$bg]['font'], $line['pretext'] . ($line['variant'] ? $$line['variant'] : "") . $line['posttext']);
}
imagepng($i);
His original had this possibly important difference. I can't remember what /var/ means here. 'filename' => 'oinkav.png', 'colour' => array(0xff,0xff,0xff), 'font' => '/var/www/gotroot.ca/media/fonts/redensek.ttf', 'size' => 10,
I chmod'd /media/ to 777, then put this .php, pixeleater.png, and /font/segoeui.ttf inside. What super basic thing am I overlooking? I don't see how pixeleater.png could be the bg and generate new images also named pixeleater.png.
I'm open to using any script, I just wish this would work.