Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. GTANet.com

    2. GTANet 20th Anniversary

    1. GTA Online

      1. The Cayo Perico Heist
      2. Find Lobbies & Players
      3. Guides & Strategies
      4. Vehicles
      5. Content Creator
      6. Help & Support
    2. Red Dead Online

      1. Frontier Pursuits
      2. Find Lobbies & Outlaws
      3. Help & Support
    3. Crews

    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. Grand Theft Auto Series

      1. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
    6. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
    7. GTA III

      1. Guides & Strategies
      2. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Support

      1. Court House
    3. Suggestions

[REL|PHP] Winamp "Now Playing" Sig


Jack_Knife

Recommended Posts

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
Link to post
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 post
Share on other sites
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.

Link to post
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

Link to post
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 post
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 post
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.

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

Link to post
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.

Link to post
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 post
Share on other sites

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
Link to post
Share on other sites

@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:

Link to post
Share on other sites
  • 3 weeks later...
  • 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 post
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.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • 2 Users Currently Viewing
    0 members, 0 Anonymous, 2 Guests

×
×
  • Create New...

Important Information

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