|
Post by acoolie530 on Mar 4, 2006 20:36:06 GMT
Well, Last.fm has a limit on how often you can request their server. There are some people with signatures from some Dutch website, but the problem is that these signatures are generated on load. Which causes a waste of server load and also a chance on being banned from Last.fm So, I wrote this little script a few days ago. There are a lot of variables to edit at the top, so I guess I will document them all here. ExampleSource$username - Your last.fm or audioscrobbler username $title - The title to display above the tracks $linewidth - The width of the line beneath the title $titlestart - The title size $speed - How often the image is updated $type - The rss feed to update from. I use recenttracks, but others are available. $notracksmess - The message to display when there are no results $total - The number of tracks to display $size - The font size for the tracks $width - The width of the image $height - The height of the image $bgcolor - An array of rgb colors for the background $color - An array of rgb colors for the text $font - The location of the font to use $tracksxml - Do not edit $imagedir - The directory to store the image in. Must be chmodded to 0777InstructionsDownload the source. Edit the variables documented above. Namely $username and $title. Make sure that $font is the location of a valid .ttf font file. Create the directory last.fm (Or whatever you changed $imagedir to) and chmod it to 0777. Place the following code in your signature, but change it to the location of your last.php: [img src="http://www.example.com/path/to/you/last.php?.gif"]The ?.gif is important. Comments, critique, suggestions, help, post here =D
|
|
|
Post by mukei on Mar 4, 2006 20:51:22 GMT
It's a nice piece of work you've gotten there. I'd suggest having areas for more customization for images(borders, gradients, backgrounds,etc;). Good work
|
|
|
Post by acoolie530 on Mar 4, 2006 20:53:44 GMT
Hmm, it is already hard to implement most imaging functions with this because PHP GD is not very complex. Gradients and backgrounds would definately be hard to do. Borders would probably be pretty easy.
|
|
|
Post by 11823 on Mar 4, 2006 21:17:19 GMT
You didnt see my reply over at PBS so I thought Ill post here I have a problem! This is the location of the folder: www.blisworthfc.com/jamie/last.fmIt has been CHMOD to 777 This is the source im using: <?php
// Last.fm tracks // Created by ACoolie
header('Content-Type: image/png');
$username = 'jjmundy'; $title = 'Jamie\'s Recent Tracks'; // The title to display at the top of your image $linewidth = 96; // The width of the underline $titlestart = 6; // The line to start the title on
$speed = 5; // How often the image is regenerated. Useless to be larger than your smallest song length.
$type = 'recenttracks'; // Can be topalbums, topartists, toptracks, friends, neighbours, recenttracks, tags, taggeditems, artisttags, albumtags, tracktags, journals, weeklychartlist, weeklyartistchart, weeklytrackchart, weeklyalbumchart, profile, manualrecs, weeklyrecs, wikirecs $notracksmess = 'No Recent Tracks.'; // The message to display if there are no recent tracks $total = 5; // The total number of tracks to display
$size = 6; // The font size
$width = 250; // The image width $height = 50; // The image height
$bgcolor = array(243, 243, 243); // Red/Green/Blue values for the background color. 243/243/243 is the background color for SSD. $color = array(0, 0, 0); // Red/Green/Blue values for the text color. 0/0/0 is black.
$font = 'http://www.blisworthfc.com/jamie/last.fm/04b03.ttf'; // The location of the font $tracksxml = 'http://ws.audioscrobbler.com/1.0/user/' . $username . '/' . $type . '.rss'; $imagedir = 'http://www.blisworthfc.com/jamie/last.fm/';
$date = floor(date('i') / $speed) * $speed;
if (file_exists($imagedir . $date . '.png')) { readfile($imagedir . $date . '.png'); } else { if ($dh = opendir($imagedir)) { while ($file = readdir($dh)) { if (substr($file, 0, 1) !== '.') unlink($imagedir . $file); } } $img = imagecreate($width, $height); $white = imagecolorallocate($img, $bgcolor[0], $bgcolor[1], $bgcolor[2]); $black = imagecolorallocate($img, $color[0], $color[1], $color[2]); imagettftext($img, $titlestart, 0, 0, $titlestart, $black, $font, $title); imageline($img, 0, $titlestart + 1, $linewidth, $titlestart + 1, $black); $contents = file_get_contents($tracksxml); preg_match_all('/<item>.*<title>(.+)<\/title>.*<\/item>/isU', $contents, $matches, PREG_SET_ORDER); if (count($matches) > 0) { $matches = array_slice($matches, 0, $total); $off = $size + 2; $i = $off * 2; foreach ($matches as $match) { imagettftext($img, $size, 0, 0, $i, $black, $font, html_entity_decode($match[1])); $i += $off; } } else { imagettftext($img, $size, 0, 0, $i, $black, $font, $notracksmess); } imagesavealpha($img, true); imagealphablending($img, false); imagepng($img, $imagedir . $date . '.png'); imagepng($img); imagedestroy($img); }
?>
What am I doing wrong? -Jamie Edit: When I view the image it says it contains errors
blisworthfc.com/jamie/last.php?.gif
|
|
|
Post by acoolie530 on Mar 4, 2006 21:26:29 GMT
First of all, the font has to be in a seperate folder than last.fm. That folder is automatically truncated on every load.
Otherwise, make all of the directories local. Change $imagedir to "last.fm/" (without quotes) and $font to "font/04b03.ttf" (without quotes, if font is the name of the directory you placed 04b03.ttf in).
If that doens't work, place to slashes ("/") before the "header()" line at the top. Then, send me the error message.
|
|
|
Post by 11823 on Mar 4, 2006 21:36:57 GMT
First of all, the font has to be in a seperate folder than last.fm. That folder is automatically truncated on every load. Otherwise, make all of the directories local. Change $imagedir to "last.fm/" (without quotes) and $font to "font/04b03.ttf" (without quotes, if font is the name of the directory you placed 04b03.ttf in). If that doens't work, place to slashes ("/") before the "header()" line at the top. Then, send me the error message. Your absoloutely amazing! I got it to work! Thanks so so os much! Your awesome! Thanks!
|
|
|
Post by mukei on Mar 4, 2006 22:55:06 GMT
Also, not only giving the user the choice of font, you could also allow them to change the size of the font. But if might be a bit difficult. Just a suggestion
|
|
|
Post by Josh on Mar 4, 2006 23:28:00 GMT
Also, not only giving the user the choice of font, you could also allow them to change the size of the font. But if might be a bit difficult. Just a suggestion You can do both with the script. And why would it be hard to add a bg image? I'm not a PHP wiz or anything, but I was modifying an open source one a while ago and it told me to just add in something like background="blah" and it worked. Though I never got the color of the font to change.
|
|
|
Post by acoolie530 on Mar 5, 2006 3:12:31 GMT
I guess background wouldn't be that hard.
Just using imagecreatefrompng($backgroud), but still =P
|
|
|
Post by Curious George® on Mar 6, 2006 17:13:24 GMT
ok your turn to help me out what could be wrong? georgelittle.2plans.com/siggyive chmodded siggy to 777 and also last.fm to 777 still getting errors [06-Mar-2006 12:13:05] PHP Fatal error: Call to undefined function: imagettftext() in /home/georgeli/public_html/siggy/last.php on line 51
|
|
|
Post by acoolie530 on Mar 6, 2006 20:34:40 GMT
Your host does not support GD extension. Try this code and tell me if it works: var_dump(gd_info());
|
|
|
Post by Curious George® on Mar 6, 2006 21:15:06 GMT
where would i add it into the code?
|
|