Jump to content

[REL|PHP] Winamp "Now Playing" Sig


Jack_Knife

Recommended Posts

Jack_Knife

Well, after getting two requests in like, half an hour of having it as my sig, I figured I'd post the code. Just change the username to your Audioscrobbler one, and upload to your PHP-enabled web server, and that's it.

 

nowplaying.php:

 

<?// Set content type headerheader("Content-type: image/png");// Constants$charWidth = 7;$charWidthDisp = 6;$charHeight = 10;$chars = array("." => 11, ":" => 12, "(" => 13, ")" => 14, "-" => 15, "'" => 16, "!" => 17,      "_" => 18, "+" => 19, "\\" => 20, "/" => 21, "[" => 22, "]" => 23, "^" => 24,      "&" => 25, "%" => 26, "," => 27, "=" => 28, "$" => 29, "#" => 30);// Variables$username = "Jack_Knife"; // Change this to your Audioscrobbler username// Retrieve name of last song played and formatlist(,$song) = explode("\n", @file_get_contents("http://ws.audioscrobbler.com/txt/recent/".$username));if (!isset($song) || strlen($song) == 0) { $song = "Not playing anything";}$song = strtoupper($song);if (strlen($song) > 41) $song = substr($song, 0, 38)."...";// Load the background image and set transparency$image = imagecreatefrompng("background.png");$green = imagecolorallocate($image, 0, 255, 0);$trans = imagecolortransparent($image, $green);// Load the font image$fontImage = imagecreatefrompng("font.png");// Loop through string printing a character at a time$startX = 32;$startY = 31;for ($i=0; $i<strlen($song); $i++) { $char = $song[$i]; $asc = ord($char); switch ($asc) { 	case ($asc >= 65 && $asc <= 90): // Letters   imagecopy($image, $fontImage, $startX + $i * $charWidthDisp, $startY, ($asc - 65) * $charWidth, 0, $charWidth, $charHeight);   break; 	case ($asc >= 48 && $asc <= 57): // Numbers   imagecopy($image, $fontImage, $startX + $i * $charWidthDisp, $startY, ($asc - 48) * $charWidth, $charHeight, $charWidth, $charHeight);   break; 	case 34: // "   imagecopy($image, $fontImage, $startX + $i * $charWidthDisp, $startY, 26 * $charWidth, 0, $charWidth, $charHeight);   break; 	case 64: // @   imagecopy($image, $fontImage, $startX + $i * $charWidthDisp, $startY, 27 * $charWidth, 0, $charWidth, $charHeight);   break; 	default: // All other characters   if (isset($chars[$char])) imagecopy($image, $fontImage, $startX + $i * $charWidthDisp, $startY, $chars[$char] * $charWidth, $charHeight, $charWidth, $charHeight);   break; }}// Output image and clean upimagepng($image);imagedestroy($image);?>

 

 

You'll also need background.png and font.png

 

background.png:

user posted image

 

font.png:

user posted image

 

Upload the three files, and you're done. I know the code ain't too good, but it was kinda rushed, plus the stupid winamp font image doesn't have the characters in the same order as their ASCII numbers, which made it harder.

 

Enjoy, and post any questions you may have. smile.gif

Edited by Jack_Knife

"You can play faster than Al Di Meola and do it with only one pinky, but if you're not listening to what is going on around you, you might as well just shut up"

 

isn't your croth suppose to be erecting when you have an orgasm?
Link to comment
Share on other sites

Believe it or not, I was about to make one of these, using a Winamp image, and fed from AudioScrobbler.

 

tounge.gif

 

Freaky.

Link to comment
Share on other sites

magical_trevor

Does this only work with Winamp, or does it work with all of the other audioscrobbler plugins?

Link to comment
Share on other sites

Jack_Knife

Works with all of them, it'll just show the Winamp image in your sig.

"You can play faster than Al Di Meola and do it with only one pinky, but if you're not listening to what is going on around you, you might as well just shut up"

 

isn't your croth suppose to be erecting when you have an orgasm?
Link to comment
Share on other sites

If I delete 3 random lines of code, can I still get it to work?

 

edit: I made some improvements.

 

 

<?header("Content-type: image/png"); $a=7; $b=6; $c=10; $d=array("."=>11,":"=>12,"("=>13,")"=>14,"-"=>15,"'"=>16,"!"=>17,"_"=>18,"+"=>19,"\\"=>20, "/"=>21,"["=>22,"]"=>23,"^"=>24,"&"=>25,"%"=>26,","=>27,"="=>28,"$"=>29,"#"=>30); $e="Jack_Knife"; list(,$f)=explode("\n",@file_get_contents("http://ws.audioscrobbler.com/txt/recent/".$e)); if(!isset($f)||strlen($f)==0){$f="Not playing anything"; }$f=strtoupper($f); if(strlen($f)>41)$f=substr($f, 0, 38)."..."; $g=imagecreatefrompng("background.png"); $h=imagecolorallocate($image,0,255,0); $i=imagecolortransparent($image,$green); $j=imagecreatefrompng("font.png");$x=32;$y=31;for($k=0;$k<strlen($f);$k++){$l=$f[$k];$m=ord($l);switch($m){case($m>=65&&$m<=90): imagecopy($g,$j,$x+$k*$b,$y,($m-65)*$a,0,$a,$c);break;case($m>=48&&$m<=57): imagecopy($g,$j,$x+$k*$b,$y,($m-48)*$a,$c,$a,$c);break;case 34:imagecopy($g,$j,$x+$k*$b,$y,26*$a,0,$a,$c);break;case 64:imagecopy($g,$j,$x+$k*$b,$y,27*$a,0,$a,$c);break;default:if(isset($d[$l]))imagecopy($g,$j,$x+$k*$b,$y,$d[$l]*$a,$c,$a,$c);break;}}imagepng($g);imagedestroy($g);?>

 

Edited by Hynes
Link to comment
Share on other sites

Jack_Knife
If I delete 3 random lines of code, can I still get it to work?

Actually, yes, I can see 3 lines that can be deleted while still allowing it to work. Chances of you picking those 3 lines at random are like, not good, but. But.

"You can play faster than Al Di Meola and do it with only one pinky, but if you're not listening to what is going on around you, you might as well just shut up"

 

isn't your croth suppose to be erecting when you have an orgasm?
Link to comment
Share on other sites

heh, nice. I switched to iTunes though, now it's crazy whack, two different ones on my screen wink.gif

 

Also, what about a version with just the Playing bar? My sig isn't red, honest tounge.gif

F4tISZ2.png

xY1j6rP.gif

Link to comment
Share on other sites

Now, what would have been cool, if you made it expand on amount of text.

 

Could be a bit hard since you have chosen such a static image.

 

Anyways, cool, but I don't think I'm going to look for a plugin as that for XMMS.

 

@Hynes: Thanks for copying my idea of optimizing. tounge.gif

 

EDIT: Okay, I took upon Hynes, and made it even shorter;

 

<? header("Content-type: image/png"); $w=7; $d=6; $h=10; $c=".)-'!_+\\/[]^&%,=$#";list(,$s)=explode("\n",@file_get_contents('http://ws.audioscrobbler.com/txt/recent/'.'Jack_Knife')); $s=(!isset($s)||strlen($s)==0)?'Not playing anything':$s;$s=strtoupper($s); $s=(strlen($s)>41)?(substr($s,0,38).'...'):$s; $i=imagecreatefrompng('background.png');$g=imagecolorallocate($image,0,255,0);$t=imagecolortransparent($i,$g);$f=imagecreatefrompng('font.png'); $X=32; $Y=31; for($j=0;$j<strlen($);$j++) { $q=$s[$j]; $a=ord($q); $l=($a>=65 && $a<=90)?(($a-65)*$w)($a>=48 && $a<=57)?(($a-48)*$w)($a==34)?(26*$w)($a==64)?(27*$w)(strstr($c,$q))?((strpos($c,$q)+11)*$w):''))));imagecopy($i,$f,$X+$i*$d,$Y,$l,$h,$w,$h); } imagepng($i); imagedestroy($); ?>

 

 

The only things I couldn't short was the URL, file names, and the image functions.

 

An important thing you are forgetting, Jack, is that '' should always used where "" is not needed, since "" has a lot extra features, the compiler ( PHP ), looks deeper through it, and therefore takes longer time, while PHP simply assumes that '' is a string, and nothing else.

Edited by Svip
Link to comment
Share on other sites

magical_trevor
Now, what would have been cool, if you made it expand on amount of text.

 

Could be a bit hard since you have chosen such a static image.

 

Anyways, cool, but I don't think I'm going to look for a plugin as that for XMMS.

 

@Hynes: Thanks for copying my idea of optimizing. tounge.gif

Audioscrobbler has an XMMS plugin: here, which should work with this...

Link to comment
Share on other sites

Jack_Knife
Now, what would have been cool, if you made it expand on amount of text.

 

Could be a bit hard since you have chosen such a static image.

 

Anyways, cool, but I don't think I'm going to look for a plugin as that for XMMS.

 

@Hynes: Thanks for copying my idea of optimizing. tounge.gif

 

EDIT: Okay, I took upon Hynes, and made it even shorter;

 

<? header("Content-type: image/png"); $w=7; $d=6; $h=10; $c=".)-'!_+\\/[]^&%,=$#";list(,$s)=explode("\n",@file_get_contents('http://ws.audioscrobbler.com/txt/recent/'.'Jack_Knife')); $s=(!isset($s)||strlen($s)==0)?'Not playing anything':$s;$s=strtoupper($s); $s=(strlen($s)>41)?(substr($s,0,38).'...'):$s; $i=imagecreatefrompng('background.png');$g=imagecolorallocate($image,0,255,0);$t=imagecolortransparent($i,$g);$f=imagecreatefrompng('font.png'); $X=32; $Y=31; for($j=0;$j<strlen($);$j++) { $q=$s[$j]; $a=ord($q); $l=($a>=65 && $a<=90)?(($a-65)*$w)($a>=48 && $a<=57)?(($a-48)*$w)($a==34)?(26*$w)($a==64)?(27*$w)(strstr($c,$q))?((strpos($c,$q)+11)*$w):''))));imagecopy($i,$f,$X+$i*$d,$Y,$l,$h,$w,$h); } imagepng($i); imagedestroy($); ?>

 

 

The only things I couldn't short was the URL, file names, and the image functions.

 

An important thing you are forgetting, Jack, is that '' should always used where "" is not needed, since "" has a lot extra features, the compiler ( PHP ), looks deeper through it, and therefore takes longer time, while PHP simply assumes that '' is a string, and nothing else.

Making it expand depending on the length of the string would have been easy, I just wanted it to look exactly like my Winamp window.

 

Thanks for the note about the quotes, I didn't know that. I just always use "these" because it looks nice in Notepad++ tounge.gif

"You can play faster than Al Di Meola and do it with only one pinky, but if you're not listening to what is going on around you, you might as well just shut up"

 

isn't your croth suppose to be erecting when you have an orgasm?
Link to comment
Share on other sites

Really though, is there a chance of making this fit into my sig? tounge.gif

 

sad.gif

F4tISZ2.png

xY1j6rP.gif

Link to comment
Share on other sites

Jack_Knife
And another thing, Jack, next time, make all your characters one line, like this;

 

sviip.dk/random/characters3.gif

 

It makes it a lot more easy to use.

 

( for the link these characters is used in... )

I just took the font image straight from Winamp. I could have easily edited it in Photoshop, but that wouldn't have been much of a coding challenge, would it? tounge.gif

 

@Em: I'll make a modified version, just for you and your sig. In a bit.

"You can play faster than Al Di Meola and do it with only one pinky, but if you're not listening to what is going on around you, you might as well just shut up"

 

isn't your croth suppose to be erecting when you have an orgasm?
Link to comment
Share on other sites

Loving this sh*t, Jack.

 

And I actually worked it out by myself...

Link to comment
Share on other sites

And another thing, Jack, next time, make all your characters one line, like this;

 

sviip.dk/random/characters3.gif

 

It makes it a lot more easy to use.

 

( for the link these characters is used in... )

I just took the font image straight from Winamp. I could have easily edited it in Photoshop, but that wouldn't have been much of a coding challenge, would it? tounge.gif

 

@Em: I'll make a modified version, just for you and your sig. In a bit.

There is an advantage, cause you use a lot of code to find the right positions of your characters.

 

Which is amazingly useless, lot of nonesense coding, and longer for the PHP to compile.

 

So if you make it on a straight line, like mine. You could simply create this string in your code:

 

 

$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890&$()[]\'"{};.,<>?=!:*/\\|_+-';

 

 

Then when you are checking through each character, you assume that the position of the characters in your $chars string is the same location of the characters in the image you want to load them from. And if you place them with the same width ( in my example it is 25/2 ( don't bug me about the value, it works! ) ).

 

 

for($i=0; $i < strlen($string);$i++) {//I use this; because it has to return to the right side of the "paper", when it's X value becomes a bit too high, heh.   $y = ($x > 760)?$y+20:$y;   $x = ($x > 760)?5:$x;//In case it's a tab ( \t ) it should move ahead two spaces.   $x = ($string[$i] == "\t")?$x+25:$x;//In case it's a line feed, it should go down to the next line.    if ($string[$i] == "\n") {       $y += 20;       $x = 5;//If it's just a whitespace, move ahead a space.   } elseif ($string[$i] == ' ') {       $x += 25/2;//Oh, we have to check if the character exist in our string. If it doesn't it will be ignored, and nothing will be done for it.   } elseif (strstr($chars,$string[$i])) {//strstr($a,$b) returns where it finds $b in $a, not it's postion, but everything in $a that is after where $b is found. So if $b is not in $a, then strstr() will return null or false, and thus this arguement not being true.       $pos = strpos($chars, $string[$i]);//strpos($a,$b) will return the postion of $b in $a, but remember; it starts from 0.       imagecopy($im,$j,$x,$y,$pos*(25/2),0,25/2,20);       $x += 25/2;//head up in our x rate.   }}

 

 

I hope you understand it with the comments. You can always view the source here:

 

http://sviip.dk/random/paper.php?view=source

Link to comment
Share on other sites

Nice! Been looking for one of these as i'm crap at php tounge.gif

 

Cheers man!

Link to comment
Share on other sites

Jack_Knife

Okie dokies, just use this image instead:

 

user posted image

(Still call it background.png though)

 

And change this part in the code:

 

 $startX = 32;$startY = 31;

 

 

To this:

 

 $startX = 32;$startY = 6;

 

 

And that should do it. smile.gif

 

@Svip: Yeah, I know my code is awfully complicated because of the bad image, but I wanted a small challenge, and I think my way is pretty decent considering the stupid order of the characters in the image. If I could be bothered opening Photoshop, I'd rearrange the letters, and change the code, but I'm too lazy. tounge.gif

Edited by Jack_Knife

"You can play faster than Al Di Meola and do it with only one pinky, but if you're not listening to what is going on around you, you might as well just shut up"

 

isn't your croth suppose to be erecting when you have an orgasm?
Link to comment
Share on other sites

haha, to be a really picky bastard, what would I edit to make it suit a 300px wide background.png?

 

smile.gif

 

Thanks, btw.

F4tISZ2.png

xY1j6rP.gif

Link to comment
Share on other sites

I made another of the Winamp color shemes for this.

Hope you don't mind, Jack_Knife.

 

Click here to download

 

Here it is working:

user posted image

 

 

[edit]

I'll do some more color schemes if you wish me to.

Link to comment
Share on other sites

Jack_Knife

@M16: Post the background you're talking about, and I'll post the code. tounge.gif

 

@Waste: Nice work, I was gonna do that myself, but didn't get around to it.

 

@Jay: Yeah, I do rock. :thrust:

"You can play faster than Al Di Meola and do it with only one pinky, but if you're not listening to what is going on around you, you might as well just shut up"

 

isn't your croth suppose to be erecting when you have an orgasm?
Link to comment
Share on other sites

Nah, don't need a thinner one actually, won't be able to read the track names then. smile.gif

F4tISZ2.png

xY1j6rP.gif

Link to comment
Share on other sites

  • 3 weeks later...

If you can put images on there you can. Just use http://www.yourdomain.com/nowplaying.php as the address for the image.

"You can play faster than Al Di Meola and do it with only one pinky, but if you're not listening to what is going on around you, you might as well just shut up"

 

isn't your croth suppose to be erecting when you have an orgasm?
Link to comment
Share on other sites

You penis-face, I had that idea/released the code ages ago. mad.gif

 

But your code is much nicer. biggrin.gif

oVAzxRq.png
Link to comment
Share on other sites

  • 3 weeks later...
Sorry for replying to an old topic, but can you get this coding to go directly into your WinAMP. To where you dotn knee AudioScroober and ny of those. Its hooked directly into WinAMP and gets the song and such.
Link to comment
Share on other sites

@anuj: tounge.gif

 

@Sniper: Sorry for not seeing your post till now. Unfortunately, with my code, you need to use Audioscrobbler to use it. There are other plugins you can use with Winamp to achieve the same thing, and I believe Azkoyen posted a topic with code for other plugins a while back.

"You can play faster than Al Di Meola and do it with only one pinky, but if you're not listening to what is going on around you, you might as well just shut up"

 

isn't your croth suppose to be erecting when you have an orgasm?
Link to comment
Share on other sites

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.