last.fm dynamic signature
If you are a last.fm and Facebook fan, you might have noticed that there are already few last.fm applications out there. http://www.facebook.com/apps/index.php?q=last.fm should enlist these applications. Ever wonder how do two different website communicates with each other? Ever thought of building such applications?
Now, take a look at these official signatures at http://www.last.fm/tools/charts/ ; a user can put these as email signature, forum signature. As they states, “Images are saved locally on our servers, so don’t fret if your chart is slightly behind your profile page from time to time.” I’ve found they do not update in less than 30 minutes.

Why not we build our own signature that does the same as official last.fm signature but does not print cached data? :-D
In this post, I’m going to give you some clue.
Data Feed
Much of the data available to view on Last.fm is available in several formats through the last.fm’s Audioscrobbler Web Services API at http://www.audioscrobbler.net/data/webservices/ . We are interested in User Profile Data -> Recent Tracks which enlists 10 recently played tracks for a user. Data are available in Plain, XML, XSPF, RSS format. Here’s a sample Plain format:
1199935436,Lindsay Lohan – Anything but Me
Now you see the form is: {timestamp},{artist}{whitespace}{dash}{whitespace}{song-title}
All we need to do are: fetch, manipulate and put data and output in an image format.
Creating Dynamic Image
Like many other developers we are much interested in PHP GD library. Hundreds of articles are out there on creating images using PHP GD lib; I recommend you to go through http://www.phpmix.org/how_to_create_a_dynamic_signature/creating_your_first_dynamic_signature and do some practice
Sample Code
Here I wrote PHP Code that does output a last.fm signature. Functions and variables, I used here, are pretty self-explanatory; in case you need to learn these functions visit PHP documentation.
Screenshot
 static snapshot
 dynamic signature from mysignature.nsuers.com






how do i display relative song time? so instead of a date and time i get last listened: x minutes ago?
p.s. she je boshe ache rocks^^
Download source code.
On index.php find line:
$playTime[$i]=date(”d M h:i a”,mktime($playtime["hours"]+10,$playtime["minutes"],$playtime["seconds"],$playtime["mon"],$playtime["mday"]));
replace with:
$play_time_ago = getdate( time() – mktime($playtime["hours"] + 10, $playtime["minutes"], $playtime["seconds"], $playtime["mon"], $playtime["mday"]) );
$playTime[$i] = $play_time_ago['mday']. “d:”.$play_time_ago['hours']. “h:”. $play_time_ago['minutes']. ” m ago”;
the modification will print [X1]d:[X2]h:[X3]m ago instead of playtime; where d=days, h=hours and m=minutes.
and if you want, you can convert day and hour values into minutes to get output as “.. X minutes ago”.
p.s: before deducting playtime from current time, you may need to adjust $play_time_ago ‘caz time() gives you the server time where you are running this script and $playtime holds last.fm server time.
Warning: Cannot modify header information – headers already sent by (output started at C:\xampp\htdocs\har\index.php:1) in C:\xampp\htdocs\har\index.php on line 75
ups! but I can’t help without seeing your code. anyway, check this script, save as .php file.
snapshots:
Playtime view
X Mins Ago – view
Got your one buddy. Think the problem was with PHP4. Works cool in my server.
http://www.elvista.co.cc/siggy/b.php
thank’s for all your help mate^^
changed the link:
http://www.elvista.co.cc/siggy/
again, thanks ^^
cool (Y)! nice background
Realy nice, your dynamic signature gave me another idea for it!