Since this was requested in a thread a while back and nobody has gotten around to making a tutorial, I thought I'd post my code with some comments included. If you have any questions, post here
Example (not live):
- Code: Select all
<?
//Subsonic Account Information
$username = "admin";
$password = "";
//Path to your Subsonic
$subsonicpath = "http://www.domain.com/subsonic";
//Path to your signature image
$signaturepath = "images/signature.jpg";
//Font settings
$size = 4;
$x = 5; //X Position
$y = 97; //Y Position
$color = imagecolorallocate($img,255,255,255);
//Retrieve the XML output from REST
$xmlstr = simplexml_load_file("$subsonicpath/rest/getNowPlaying.view?u=$username&p=$password&v=1.3.0&c=forumsig");
//Retrieve Now Playing Information
$artist = $xmlstr->nowPlaying->entry[artist];
$title = $xmlstr->nowPlaying->entry[title];
$year = $xmlstr->nowPlaying->entry[year];
$bitrate = $xmlstr->nowPlaying->entry[bitRate];
$minutesago = $xmlstr->nowPlaying->entry[minutesAgo];
//Change header to jpeg, so browsers know that this is an image
header('Content-Type: image/jpeg');
$img = @imagecreatefromjpeg($signaturepath);
if ($artist && $title) //Check if a song is playing or not, if not, don't write anything!
imagestring($img, $size,$x,$y, "Subsonic: $artist - $title ($minutesago min. ago)",$color);
imagejpeg($img);
imagedestroy($img);
?>