This will require 3 files, all in the same directory. So, of course you will need access to the space, you will need access to create an .htaccess file (if worse comes to worse, your host may place the file for you), and you need php access.
First, create an .htaccess file in the directory, and enter in the following:[code]AddType application/x-httpd-php jpg
AddType application/x-httpd-php png
AddType application/x-httpd-php gif[/code]Next, create a file called sig.jpg (or whatever else) and place ONLY this code in it:[code]<?php include(\'sig.php\');?>[/code]Now comes the fun part. Create a file called \'sig.php\', and add this code to it... be sure to edit it to your liking (as I said, this is simplictic):[code]<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); //Will never cache the image
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); //Set date to creation (viewing) of file
header("Cache-Control: no-store, no-cache, must-revalidate"); //Do Not Cache, Store, or otherwise view older copies of the image
header("Cache-Control: post-check=0, pre-check=0", false); //Ditto
header("Pragma: no-cache"); //Duh
Header("Content-type: image/jpeg"); //THis is to create an Image, so read it as such
// Fill in your own server information here:
$host = "radio.lethargy.ws"; //Insert your Online Radio Server IP or Host Here
$port = "8000"; //The Port the radio broadcasts on... most often, 8000 is used
$listenlink = \'http://radio.lethargy.ws:8000/listen.pls\'; //make link to stream
$fp = fsockopen("$host", $port, &$errno, &$errstr, 30); //open connection
if(!$fp) {
$success=2; //se-t if no connection
}
if($success!=2){ //if connection
fputs($fp,"GET /7.html HTTP/1.0\r\nUser-Agent: XML Getter (Mozilla Compatible)\r\n\r\n"); //get 7.html... this is the info page
while(!feof($fp)) {
$page .= fgets($fp, 1000);
}
fclose($fp); //close connection
$page = ereg_replace(".*<body>", "", $page); //extract data
$page = ereg_replace("</body>.*", ",", $page); //extract data
$numbers = explode(",",$page); //extract data
$currentlisteners=$numbers[0]; //set variable
$connected=$numbers[1]; //set variable
if($connected==1) //if DSP is connected
$wordconnected="yes"; //set variable
else //if no DSP connection
$wordconnected="no"; //set variable
$peaklisteners=$numbers[2]; //set variable
$maxlisteners=$numbers[3]; //set variable
$reportedlisteners=$numbers[4]; //set variable
$bitrate=$numbers[5]; //set variable
}
$im = ImageCreate(450,53); //300 px wide, 53px high
$background_color = ImageColorAllocateAlpha($im,255,0,255,127); //This is clear background
$text_color1 = ImageColorAllocate($im,255,0,0); //The Font Colour, to be used during image creation (see later)
$text_color2 = ImageColorAllocate($im,255,0,0); //Secondary font colour, if you want to use more than one colour
if($success!=2 && $connected==1){
$song=explode(" - ",$numbers[6]);
$string1= "Lethargy/Isyourgod Online Radio"; // Insert the first line to display... often the Radio Title
$string2= "Currently Playing: ".$song[0]; //Current Playing Artist
$string3= "Song: ".$song[1]." ".$song[2]." ".$song[3]." ".$song[4]; //Current Playing Song, and any other info about song (if title is long)
$string4= "Coming To You At ".$numbers[5]." KBPS"; //KBps The Radio Station Is Broadcasting At
}
else {
$string1= ""; //Empty String... This and the following lines are for when radio is offline
$string2= "Lethargy/Isyourgod Radio is currently"; //Second Line To Say When Offline
$string3= "Offline!."; //Ditto
$string4= ""; //Another Empty Line
}
//The following lines are the alignment and font for the lines as they are displayed... play with it for proper playing and the font you like most
$px = (imagesx($im)-5*strlen($string1))/2;
ImageString($im,3,$px,10,$string1,$text_color1); //Easiest way to explain this is http://us3.php.net/imagestring
$px = (imagesx($im)-5*strlen($string2))/2;
ImageString($im,2,$px,20,$string2,$text_color1); //imagestring ( resource image [use $im], int font [php built-in font], int x [Position from left side in px], int y [distance from top in px], string s, int colour)
$px = (imagesx($im)-5*strlen($string3))/2;
ImageString($im,2,$px,30,$string3,$text_color1); //imagestring ( resource image [use $im], int font [php built-in font], int x [Position from left side in px], int y [distance from top in px], string s, int colour)
$px = (imagesx($im)-5*strlen($string4))/2;
ImageString($im,2,$px,40,$string4,$text_color1); //imagestring ( resource image [use $im], int font [php built-in font], int x [Position from left side in px], int y [distance from top in px], string s, int colour)
ImagePng($im); //Create the actual image for display
ImageDestroy($im); //Remove the image from memory
?>[/code]I tried to comment through the file as much as I could, just so you know what it is doing, and what can be easily edited... but this should give some people a head start on what they need to do to make this, or another dynamic image. The key part is the htaccess file, as it tells the system to read the php inside the image as php code, instead of as a corrupt image.
The nicest thing to this, is that you do NOT need admin access to the Shoutcast server to set this up... something that sets it apart from other options.
The end result:[img]http://www.isyourgod.com/NS_Sig/sig.jpg[/img]
Simplistic Winamp 'Now Playing" image
Moderators: Moderator, Global Moderator
-
NightStorm
- Administrator

- Posts: 778
- Joined: Mon May 17, 2004 4:05 pm
Simplistic Winamp 'Now Playing" image
Last edited by NightStorm on Tue Aug 16, 2005 2:41 am, edited 1 time in total.
Simplistic Winamp 'Now Playing" image
Nice NS <img src=\'http://www.killanet.net/forum3/public/s ... >/good.gif\' class=\'bbc_emoticon\' alt=\'(Y)\' />
-
NightStorm
- Administrator

- Posts: 778
- Joined: Mon May 17, 2004 4:05 pm
Simplistic Winamp 'Now Playing" image
Right now (well, not at this second, but in general) I\'m working on using a background image with it, or at the very least aligning it better (like the one in my sig). I was kinda in a rush, as I had people pounding on the door and such (something about a meeting I was supposed to be at... slackers).
-
NightStorm
- Administrator

- Posts: 778
- Joined: Mon May 17, 2004 4:05 pm
Simplistic Winamp 'Now Playing" image
Adding a background image... you\'ll want to play with the text alignment to make it fit with whatever background you chose, though[code]<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); //Will never cache the image
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); //Set date to creation (viewing) of file
header("Cache-Control: no-store, no-cache, must-revalidate"); //Do Not Cache, Store, or otherwise view older copies of the image
header("Cache-Control: post-check=0, pre-check=0", false); //Ditto
header("Pragma: no-cache"); //Duh
Header("Content-type: image/jpeg"); //This is to create an Image, so read it as such
$im = imagecreatefrompng("sc_back.png"); // This will be the background image
$host = "radio.lethargy.ws"; //Shoutcast Host (or IP)
$port = "8000"; //Shoutcast Port
$listenlink = \'radio.lethargy.ws:8000/listen.pls\'; //URL to the listen link, without the http://
$fp = fsockopen("$host", $port, &$errno, &$errstr, 30); //Opens a socket to the Shoutcast server
if(!$fp) {
$success=2;
}
if($success!=2){
fputs($fp,"GET /7.html HTTP/1.0\r\nUser-Agent: XML Getter (Mozilla Compatible)\r\n\r\n"); //Grab 7.html (contains all the needed data)
while(!feof($fp)) {
$page .= fgets($fp, 1000);
}
fclose($fp);
$page = ereg_replace(".*<body>", "", $page); //extract data
$page = ereg_replace("</body>.*", ",", $page); //extract data
$numbers = explode(",",$page); //extract data
$currentlisteners=$numbers[0]; //How many connections are in use
$connected=$numbers[1]; //How many unique listeners
if($connected==1)
$wordconnected="yes";
else
$wordconnected="no";
$peaklisteners=$numbers[2]; //Set a variable for the Peak Listeners
$maxlisteners=$numbers[3]; //Set a Variable For The Max Listeners (total available spaces)
$reportedlisteners=$numbers[4]; //How many people are listening
}
$text_color1 = ImageColorAllocate($im,255,255,255); //Set Text Color 1
$text_color2 = ImageColorAllocate($im,0,0,0); //Set Text Color 2 (Used if you will be using more than one color)
if($success!=2 && $connected==1){ //If we are connected, proceed... or else, jump to else
$song=explode(" - ",$numbers[6]);
$string1= $numbers[5]."kbps With ".$currentlisteners." Listeners (".$maxlisteners." Slots)"; //First Line Of Text... can be anything you want
$string2= $song[1]." ".$song[2]." ".$song[3]." ".$song[4]; //Second Line Of Text
$string3= $song[0]; //Third Line Of Text
}
else { //If we are not connected, proceed
$string1= "The Radio is currently Offline"; //First Line To Display When Radio is Offline
$string2= "No Song Currently Playing"; //Second Line To Display When Radio is Offline
$string3= "No Song Currently Playing"; //Third Line To Display When Radio is Offline
}
ImageString($im,5,187,27,$string1,$text_color1); //Set The First Line Of Text On The Image
ImageString($im,5,119,48,(substr($string2, 0, 40) . "..."),$text_color1); //Set The Second Line Of Text... after 40 characters, cut off with ...
ImageString($im,5,75,70,$string3,$text_color1); //Set The Third Line Of text
ImagePng($im); //Display The Image
imagedestroy($im); //Remove The Image From Memory
?>[/code]
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); //Will never cache the image
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); //Set date to creation (viewing) of file
header("Cache-Control: no-store, no-cache, must-revalidate"); //Do Not Cache, Store, or otherwise view older copies of the image
header("Cache-Control: post-check=0, pre-check=0", false); //Ditto
header("Pragma: no-cache"); //Duh
Header("Content-type: image/jpeg"); //This is to create an Image, so read it as such
$im = imagecreatefrompng("sc_back.png"); // This will be the background image
$host = "radio.lethargy.ws"; //Shoutcast Host (or IP)
$port = "8000"; //Shoutcast Port
$listenlink = \'radio.lethargy.ws:8000/listen.pls\'; //URL to the listen link, without the http://
$fp = fsockopen("$host", $port, &$errno, &$errstr, 30); //Opens a socket to the Shoutcast server
if(!$fp) {
$success=2;
}
if($success!=2){
fputs($fp,"GET /7.html HTTP/1.0\r\nUser-Agent: XML Getter (Mozilla Compatible)\r\n\r\n"); //Grab 7.html (contains all the needed data)
while(!feof($fp)) {
$page .= fgets($fp, 1000);
}
fclose($fp);
$page = ereg_replace(".*<body>", "", $page); //extract data
$page = ereg_replace("</body>.*", ",", $page); //extract data
$numbers = explode(",",$page); //extract data
$currentlisteners=$numbers[0]; //How many connections are in use
$connected=$numbers[1]; //How many unique listeners
if($connected==1)
$wordconnected="yes";
else
$wordconnected="no";
$peaklisteners=$numbers[2]; //Set a variable for the Peak Listeners
$maxlisteners=$numbers[3]; //Set a Variable For The Max Listeners (total available spaces)
$reportedlisteners=$numbers[4]; //How many people are listening
}
$text_color1 = ImageColorAllocate($im,255,255,255); //Set Text Color 1
$text_color2 = ImageColorAllocate($im,0,0,0); //Set Text Color 2 (Used if you will be using more than one color)
if($success!=2 && $connected==1){ //If we are connected, proceed... or else, jump to else
$song=explode(" - ",$numbers[6]);
$string1= $numbers[5]."kbps With ".$currentlisteners." Listeners (".$maxlisteners." Slots)"; //First Line Of Text... can be anything you want
$string2= $song[1]." ".$song[2]." ".$song[3]." ".$song[4]; //Second Line Of Text
$string3= $song[0]; //Third Line Of Text
}
else { //If we are not connected, proceed
$string1= "The Radio is currently Offline"; //First Line To Display When Radio is Offline
$string2= "No Song Currently Playing"; //Second Line To Display When Radio is Offline
$string3= "No Song Currently Playing"; //Third Line To Display When Radio is Offline
}
ImageString($im,5,187,27,$string1,$text_color1); //Set The First Line Of Text On The Image
ImageString($im,5,119,48,(substr($string2, 0, 40) . "..."),$text_color1); //Set The Second Line Of Text... after 40 characters, cut off with ...
ImageString($im,5,75,70,$string3,$text_color1); //Set The Third Line Of text
ImagePng($im); //Display The Image
imagedestroy($im); //Remove The Image From Memory
?>[/code]
Simplistic Winamp 'Now Playing" image
Awesome!
How long did that take you?
How long did that take you?
-
NightStorm
- Administrator

- Posts: 778
- Joined: Mon May 17, 2004 4:05 pm
Simplistic Winamp 'Now Playing" image
With google, babelfish (most of the examples I found were not in English) and php.net?
About an hour.
Setting up my sig? ABout 10 minutes, once Jeremy sent the template for the background. The hardest part is in figuring the alignment out for the text.
About an hour.
Setting up my sig? ABout 10 minutes, once Jeremy sent the template for the background. The hardest part is in figuring the alignment out for the text.


