kewlhotrod

Untitled

Dec 8th, 2011
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. <?php
  2.  
  3. $url = 'http://199.19.105.66/asstats-xml.xsl';
  4. $db_file = './playlist.history';
  5. $fontFile = './LCD.TTF';
  6.  
  7. $xmlData = file_get_contents($url);
  8. $titles = array();
  9. $ntitles = array();
  10. $charWidth = 10;
  11. $lineWidth = 0;
  12. $boxWidth = 0;
  13. $lineHeight = 20;
  14. $boxHeight = 0;
  15. $boxPad = 10;
  16. if ($xmlData != "") {
  17. if (preg_match_all('@<stitle>(.+?)</stitle>@is', $xmlData, $ntitles)) {
  18. if (!empty($ntitles[1])) {
  19. foreach ($ntitles[1] as $title) {
  20. $titles[] = trim($title);
  21. }
  22. }
  23. } else {
  24. $titles[] = 'No songs are being played currently.';
  25. }
  26. } else {
  27. $titles[] = 'Nope';
  28. }
  29.  
  30. foreach ($titles as $title) {
  31. $boxHeight += $lineHeight;
  32. $lineWidth = $charWidth * strlen($title);
  33. if ($boxWidth < $lineWidth) {
  34. $boxWidth = $lineWidth;
  35. }
  36. }
  37.  
  38. $boxWidth += $boxPad * 2;
  39. $boxHeight += $boxPad * 2;
  40. $image = imagecreatetruecolor($boxWidth, $boxHeight);
  41. $bgColor = imagecolorallocate($image, 51, 51, 51);
  42. imagefilledrectangle($image, 0, 0, $boxWidth, $boxHeight, $bgColor);
  43. $textColor = imagecolorallocate($image, 255, 255, 255);
  44.  
  45. $i = 0;
  46. foreach ($titles as $title) {
  47. imagettftext($image, 12, 0, $boxPad, $lineHeight * $i + $boxPad * 2, $textColor, $fontFile, '* ' . $title);
  48. $i++;
  49. }
  50. //print_r($titles);
  51. header('Content-type: image/png');
  52. imagepng($image);
  53. imagedestroy($image);
  54. file_put_contents($db_file, implode("\r\n " . date('H:i:s A d/m/Y') . ' ', $titles), FILE_APPEND);
  55. ?>
  56.  
Advertisement
Add Comment
Please, Sign In to add comment