Volkova

PHP Now Playing V0.01

Jun 27th, 2011
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.90 KB | None | 0 0
  1. <?php
  2. /*
  3. *    +--------------------------------------------------------------+
  4. *    | Volkova Now Playing                                          |
  5. *    +--------------------------------------------------------------+
  6. *    |                                                              |
  7. *    | Author: Ryan                                                 |
  8. *    | Version: 0.01                                                |
  9. *    |                                                              |
  10. *    | This version also needs a base image, in this example it is  |
  11. *    | "Big-Image.png" that is being used                               |
  12. *    +--------------------------------------------------------------+
  13. */
  14. error_reporting(0); //If you can not connect to the url you get an error, so by turning error reporting off, you avoid this.
  15.  
  16. $name = "Ryan";
  17. $url = "http://2.126.10.113/now_playing.txt"; //The file that now_playing.py saves the current song to.s
  18.  
  19. function get_url_contents($url){
  20.     $crl = curl_init();
  21.     $timeout = 3;
  22.     curl_setopt ($crl, CURLOPT_URL,$url);
  23.     curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
  24.     curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
  25.     $ret = curl_exec($crl);
  26.     curl_close($crl);
  27.     return $ret;
  28. }
  29.  
  30. $str = get_url_contents($url);
  31.  
  32. $im = imagecreatefrompng("big-image.png");
  33. if(!$im) { die("Image Niggered up");}
  34.  
  35. $black = imagecolorallocate($im, 0, 0, 0);
  36. $green = imagecolorallocate($im, 121, 212, 121);
  37. $red = imagecolorallocate($im, 209, 62, 62);
  38.  
  39. $font = 1;
  40.  
  41. $length = strlen($name) + 5; // The "+ 5" is the " is: "
  42.  
  43. $length = $length * 18;
  44.  
  45. imagestring($im,$font,5, 5,"$name is currently listening to: ",$black);
  46.  
  47. if ( $str ) {
  48.     imagestring($im, $font, $length, 5,  "$str", $green);
  49. } else {
  50.     imagestring($im, $font, $length, 5,  "Nothing, because he's offline", $red);
  51. }
  52.  
  53. Header('Content-type: image/png');
  54.  
  55. imagepng($im);
  56.  
  57. imagedestroy($im);
  58.  
  59. ?>
Advertisement
Add Comment
Please, Sign In to add comment