Just installed this a while ago (earlier today), and I can't get the "text" part of the image working, or the cover art. I just have a "stock" image, no matter if I am listening to something or not.
- Code: Select all
<?php
//First collect some data:
$user = "test"; //user to monitor
$admin = "admin"; //user to get nowPlaying list
$adminpass = "(password)"; //pass to get nowPlaying list (plain or using enc:)
$server = "servername"; //Your subsonic server
$xml = @simplexml_load_file("http://".$server."/rest/getNowPlaying.view?u=".$admin."&p=".$adminpass."&v=1.5.0&c=signature");
if($xml==false) {
goto offline;
}
//Timestamp
$time = "My local time: ".date("H:i");
//If the server is online, check what the monitored user is listening or watching, and jump to the right code...
foreach($xml->children()->children() as $second_gen) {
$math = floor($second_gen['duration']/60);
if($second_gen['username']==$user and $second_gen['minutesAgo']<=$math) {
if($second_gen['isVideo']=='false') {
goto playing;
}
else{
goto watching;
}
}
}
//If user is offline, or the last file has finished playing...
nothing:
$image = imagecreatefrompng("back2.png");
$color = imagecolorallocate($image, 255, 255, 255);
$font = getcwd()."/VeraBd.ttf";
$fontSize = 16;
$fontRotation = 0;
$x = 1; //160
$y = 1; //65
$str = "Not listening to any music\nor watching any video now...";
imagettftext($image, $fontSize, $fontRotation, $x, $y, $color, $font, $str);
imagettftext($image, 12, 0, 1, 1, imagecolorallocate($image, 230, 49, 150), getcwd()."/scriptbl.ttf", $time);
//imagettftext($image, 12, 0, 65, 295, imagecolorallocate($image, 230, 49, 150), getcwd()."/scriptbl.ttf", $time);
header("Content-type: image/png");
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Fri, 19 Jan 1994 05:00:00 GMT");
header("Pragma: no-cache");
imagepng($image);
imagedestroy($image);
exit();
//If the user is playing a music file...
playing:
$image = imagecreatefrompng("back2.png");
//Get the cover art
$coverart = "http://".$server."/rest/getCoverArt.view?u=".$admin."&p=".$adminpass."&v=1.5.0&c=signature&id=".$second_gen['coverArt']."&size=100";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $coverart);
curl_setopt ($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_HEADER, false);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0);
$rawdata = curl_exec($ch);
$image2 = imagecreatefromstring($rawdata);
curl_close($ch);
$color = imagecolorallocate($image, 255, 255, 255);
$font = getcwd()."/VeraBd.ttf";
$fontSize = 12;
$fontRotation = 0;
$x = 510;
$y = 100;
$str = "Now Playing\nArtist: ".$second_gen['artist']."\nTitle: ".$second_gen['title']."\nAlbum: ".$second_gen['album'];
imagettftext($image, $fontSize, $fontRotation, $x, $y, $color, $font, $str);
imagettftext($image, 12, 0, 1, 1, imagecolorallocate($image, 230, 49, 150), getcwd()."/scriptbl.ttf", $time);
//imagettftext($image, 12, 0, 65, 295, imagecolorallocate($image, 230, 49, 150), getcwd()."/scriptbl.ttf", $time);
//Cover art location
imagecopy($image, $image2, 430, 170, 0, 0, 100, 100);
header("Content-type: image/png");
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Fri, 19 Jan 1994 05:00:00 GMT");
header("Pragma: no-cache");
imagepng($image);
imagedestroy($image);
exit();
//If the user is playing a video file...
watching:
$image = imagecreatefrompng("back2.png");
$color = imagecolorallocate($image, 255, 255, 255);
$font = getcwd()."/VeraBd.ttf";
$fontSize = 12;
$fontRotation = 0;
$x = 170;
$y = 55;
$str = "Now Watching\n".$second_gen['title'];
imagettftext($image, $fontSize, $fontRotation, $x, $y, $color, $font, $str);
imagettftext($image, 12, 0, 65, 295, imagecolorallocate($image, 230, 49, 150), getcwd()."/scriptbl.ttf", $time);
header("Content-type: image/png");
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Fri, 19 Jan 1994 05:00:00 GMT");
header("Pragma: no-cache");
imagepng($image);
imagedestroy($image);
exit();
//If the server is offline (404)...
offline:
$image = imagecreatefrompng("back2.png");
$color = imagecolorallocate($image, 255, 255, 255);
$font = getcwd()."VeraBd.ttf";
$fontSize = 16;
$fontRotation = -7;
$x = 160;
$y = 65;
$str = "My server seems to be down\nI'll get it back up as soon\nas possible...";
imagettftext($image, $fontSize, $fontRotation, $x, $y, $color, $font, $str);
imagettftext($image, 12, 0, 65, 295, imagecolorallocate($image, 230, 49, 150), getcwd()."scriptbl.ttf", $time);
header("Content-type: image/png");
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Fri, 19 Jan 1994 05:00:00 GMT");
header("Pragma: no-cache");
imagepng($image);
imagedestroy($image);exit();
exit();
?>
As you can see, I did some minor mods to the code (probably did it wrong), trying to get the image size to be a certain size, before just editing the image itself. (This didn't get the text to show either).
Not sure if this is possible with the current code, or if some minor code changes could be done to allow multiple users to use a signature file (on the same Subsonic server.)
My idea is that for each user I have on my Subsonic, each user can have their own specific signature file, such as "{username}.png" or something, so they can point their sig file to
http://website.subsonic.org/signatures/(their username).png (I'm guessing if I were to specify "{username}.png" in the code, instead of "back2.png", it would work, but how would I get the first line of code "$user" to be the actual user name?
Can this be done? What coding changes should I make to allow this?
Thanks!