[Tutorial] How to create a audio signature

Soldato
Joined
12 Jun 2005
Posts
5,361
Hi all,

To create your audio signature, follow these instructions:


Requirements:



1. Create a file called index.php and open it in notepad.



2. Paste the following code into that file and save it. Make sure you change the Last.fm username to yours!! - See yellow text in the code box below

Code:
<?php

$textfile = "tracks.txt";

if(filemtime($textfile) + (3 * 60) < time())
{

$fh1 = fopen($textfile, 'w+') or die("can't open file");
fwrite($fh1, "");
fclose($fh1);

class RSSParser {

	var $insideitem = false;
	var $tag = "";
	var $title = "";

	function startElement($parser, $tagName, $attrs) {
		if ($this->insideitem) {
			$this->tag = $tagName;
		} elseif ($tagName == "ITEM") {
			$this->insideitem = true;
		}
	}

	function endElement($parser, $tagName) {
		if ($tagName == "ITEM") {
			$textfile = "tracks.txt";
			$fh = fopen($textfile, 'a+') or die("can't open file");
			$tracks = sprintf("%s\n",(trim($this->title)));
			fwrite($fh, $tracks);
			fclose($fh);
			$this->title = "";
			$this->insideitem = false;
		}
	}

	function characterData($parser, $data) {
		if ($this->insideitem) {
		switch ($this->tag) {
			case "TITLE":
			$this->title .= $data;
			break;
			case "DESCRIPTION":
			$this->description .= $data;
			break;
			case "LINK":
			$this->link .= $data;
			break;
		}
		}
	}
}


$xml_parser = xml_parser_create();
$rss_parser = new RSSParser();
xml_set_object($xml_parser,&$rss_parser);
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$fp = fopen("http://ws.audioscrobbler.com/1.0/user/[color=yellow][b]Last.fm Account Username Here[/b][/color]/recenttracks.rss","r")
	or die("Error reading RSS data.");
while ($data = fread($fp, 4096))
	xml_parse($xml_parser, $data, feof($fp))
		or die(sprintf("XML error: %s at line %d",
			xml_error_string(xml_get_error_code($xml_parser)),
			xml_get_current_line_number($xml_parser)));
fclose($fp);
xml_parser_free($xml_parser);

}

if ($slogans = @file("tracks.txt"))
{
$slogan = $slogans[0];
} else {
$slogan = "No Recent Music";
}

function imagestrokedtext($im, $size, $angle, $x, $y, $tcolour, $scolour, $font, $text) {

imagettftext($im, $size, $angle, $x + 1, $y, $scolour, $font, $text);
imagettftext($im, $size, $angle, $x + 1, $y + 1, $scolour, $font, $text);
imagettftext($im, $size, $angle, $x + 1, $y - 1, $scolour, $font, $text);
imagettftext($im, $size, $angle, $x, $y, $scolour, $font, $text);
imagettftext($im, $size, $angle, $x, $y + 1, $scolour, $font, $text);
imagettftext($im, $size, $angle, $x, $y - 1, $scolour, $font, $text);
imagettftext($im, $size, $angle, $x - 1, $y, $scolour, $font, $text);
imagettftext($im, $size, $angle, $x - 1, $y + 1, $scolour, $font, $text);
imagettftext($im, $size, $angle, $x - 1, $y - 1, $scolour, $font, $text);

imagettftext($im, $size, $angle, $x, $y, $tcolour, $font, $text);

}

$im = imagecreatefromjpeg('background.jpg');

$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
$font = "font.TTF";

imagestrokedtext($im, 7, 0, 57, 48, $white, $black, $font, strtoupper($slogan));

header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Content-Type: image/jpeg");
imagejpeg($im,"",99);
imagedestroy($im);

?>



3. Create a file called tracks.txt and open it in notepad.



4. Paste the following code into that file and save it.

Code:
Audio Signature



5. Upload the background image you downloaded earlier (background.jpg), the font (font.TTF), the index.php file and the tracks.txt file into the same directory on you PHP enabled webhost/webserver. You should see something like the following when viewing the directory:





6. Now that they are uploaded have the direct url to the index.php file handy and ready to type, including the BB IMG tags (see below). For instance the url could be, including the IMG BB tags:

direct url to index.php said:
58208cf92d_test5435.png

7. Go to edit your signature and type the direct url to index.php code that you got in the previous section. You should see something similar to the following:





8. Click on preview to check it works, and you would see something similar to below:





9. If you see something similar then you have successfully added a audio signature and you can click save. If not you must have done something wrong whilst following instructions. If you have followed the instructions correctly, you will end up with a signature similar to the following:

index.php




Please Note: My PHP skills are pretty bad so bare that in mind. Also make sure you change the account details in the PHP file.


Hope this helps
 
Last edited:
Yeah edit to your hearts content, it was complied with other free (i hope) scripts so do as you wish.

I didnt realise they automatically create txt files so it would probably be best to read of those as said.
 
Back
Top Bottom