Sikawtic
03-20-2006, 12:59 PM
Ok, so I have the pic in my signature that shows information from this page: "http://www.kingsofchaos.com/stats.php?id=3259909"
Does anybody have a script that will let me do this? I mean... I like the one in my sig, but I'm wanting to make a more customized one.
Sorry for the lack of detail, I have to go right now,
~Sk
GrassDragon
03-20-2006, 1:48 PM
I had a script that would add my track info from an RSS feed on last.fm to a sig image so that my sig showed my last played song. PHP will do it all for you. You can grab info from an RSS feed if that site will let you and then use commands to add them to a stock image you provide and return that image when you call the script. I can't remember the commands off the top of my head, but if you can't find them by tonight I'll go hunting for that script.
Sikawtic
03-21-2006, 10:59 PM
I'll look up some tuts tomorrow. Thx for giving me the direction to look :D
But... how would I find if a page has an RSS feed?
The tuts confuse me...
Can someone write me a simple code??? lol
I just want it to
1) take a picture i have
2) add text to it
and then let you be able to put that image in a sig... it needs to refresh everytime the page w/ it on it is refreshed.
I'd like the text to be taken from the page i linked to above.
Sikawtic
03-23-2006, 9:27 PM
I'll give you a cookie...
Sikawtic
03-27-2006, 4:59 PM
I'd very much appreciate a script/link to a good tutorial. Thanks :D
~Phazanzar
Maybe move this to the programming lex?
GrassDragon
03-28-2006, 9:59 PM
Sorry! This thread slipped under my radar. Here's the script in its entirety. In the same directory as this script is a base image and a font file. When you call the script (via an image tag) it will return the base image with the text added on. It grabs info from an RSS feed at audioscrobbler.
<?
//////////Main User Config
//Audioscrobbler username
$username = "ryanprov";
//Text to display if track is currently playing
$currently_playing_txt = "Track currently playing:";
//Text to display if no track is playing
//and we're showing the last played track
//The text variable can also contain the <time> <date> or <zone>
//tags, which will insert the time/date/zone that the track
//was played
$last_played_txt = "Last track played @ <time> <zone> on <date>:";
//Text to display if the song parse failed
$parse_error_text_line_1 = "Error:";
$parse_error_text_line_2 = "Unable to parse song title from audioscrobbler.com";
//These set the top and bottom text's alignment respectively
//Can be "left" or "right"
$top_align = "right";
$bottom_align = "right";
//Number of seconds to wait between updates
$update_period = 160;
//Allow username to be specified in query string
//using "scrobblersig.php?username=USERNAME"? (true/false)
$allow_ext_user = false;
//If you only want to allow certain users to externally
//specify their usernames, place them below, in comma-seperated
//format. i.e. "user2" or "user1,user2,user3"
//Ensure that the "Allow username to be specified in query string"
//option above is also enabled for this to work.
$whitelist = "";
//The filename of the truetype font to use (.ttf)
//it must be in the same directory as this script
$font_filename = "Vera.ttf";
//Set this to true if you want the font antialiased
$antialias = true;
//The size of the font in pixels
$font_size = 8;
//Text colour (in HEX format)
$date_color = "#FFFFFF";
$track_color = "#3FD334";
//Background colour (in HEX format)
$background_colour = "#FFFFFF";
//Set to true if you want the background to be transparent
$transparent = "true";
//Time format see http://www.php.net/date for details
$time_format = "g:i A";
//Date format see http://www.php.net/date for details
$date_format = "n.j.y";
////Timezone change
//If you do not live in a GMT/UTC area set the options
//below with your timezone offset
//Timezone
$zone = "CST";
//Number of hours offset from GMT
$time_offset_hours = 6;
//Number of minutes offset from GMT
$time_offset_minutes = 0;
//Time change direction
//Set to + for timezones ahead of GMT
//and set to - for timezones behind GMT
$offset_direction = "-";
//////////////////////////////////////////////////////////
/////Begin main code - Don't fiddle past here kids :)/////
//////////////////////////////////////////////////////////
//Run over the passed GET vars stripping any fake file extensions
function remove_rubbish(&$val,$key){
global $GET_VARS;
$GET_VARS["$key"] = preg_replace("/(.*?)(\.png|\.jpg|\.gif)*/i","\\1",$val);
}
array_walk($HTTP_GET_VARS,"remove_rubbish");
//Check to see if an external user has been passed
if($GET_VARS['username'] && $allow_ext_user){
//If there is a whitelist, check this user is in it
if($whitelist != ""){
$whitelist_array = explode(",",$whitelist);
if(!in_array($GET_VARS['username'], $whitelist_array)){
die("<b>Error:</b> The username specified is not in the whitelist!");
}
}
$username = $GET_VARS['username'];
//Check if the time values have been specified
if($GET_VARS['time_format']){ $time_format = $GET_VARS['time_format']; }
if($GET_VARS['date_format']){ $date_format = $GET_VARS['date_format']; }
if($GET_VARS['hours']){ $time_offset_hours = $GET_VARS['hours']; }
if($GET_VARS['minutes']){ $time_offset_minutes = $GET_VARS['minutes']; }
if($GET_VARS['zone']){ $zone = $GET_VARS['zone']; }
//Convert the offset direction
if($GET_VARS['offset_direction'] == "minus"){
$offset_direction = "-";
}elseif($GET_VARS['offset_direction'] == "plus"){
$offset_direction = "+";
}
//Autogenerate the zone if not specified
if($GET_VARS['zone'] == "" && $GET_VARS['hours'] >= 1){
$zone = "GMT".$time_offset_direction.$time_offset_hours;
}
}
//Check to see if image type has been specified
$image_type = $GET_VARS['image_type'];
if($image_type != "jpg"){
$image_type = "png";
}
//Escape the username for filename use
$safe_username = escapeshellcmd($username);
//Check to see if the song info needs updating
if(!file_exists("./sig-$safe_username.$image_type")
|| (filectime("./sig-$safe_username.$image_type") < (time() - $update_period))){
//Grab the user track data file from audioscrobbler
$track_data = @file("http://ws.audioscrobbler.com/txt/recent/$username");
//Strip the track playing field of erroneous spaces
$track_data[0] = trim($track_data[0]);
//Check if a track is currently playing
if($track_data[0] != ""){
//Set track playing vars
$track = $track_data[0];
$text = $currently_playing_txt;
}else{
//Split the time/date field
list($day, $dayN, $month, $yearN, $timeN, $timezone) = explode(" ",$track_data[2]);
//Find the number of this month
$month_array = array('Jan' => 1, 'Feb' => 2, 'Mar' => 3, 'Apr' => 4, 'May' => 5, 'Jun' => 6,
'Jul' => 7, 'Aug' => 8, 'Sep' => 9, 'Oct' => 10, 'Nov' => 11, 'Dec' => 12);
$month = trim($month);
$monthN = $month_array["$month"];
//Split the time into component parts
list($hour,$min,$sec) = explode(":", $timeN);
//Generate the unix timestamp
$timestamp = mktime($hour, $min, $sec, $monthN, $dayN, $yearN);
//Calculate the time offset
$offset = (3600 * $time_offset_hours) + (60 * $time_offset_minutes);
$offset = $offset_direction.$offset;
//Calculate the modified time using offset
$new_timestamp = $timestamp + $offset;
//Generate the new time/date
$time = date($time_format, $new_timestamp);
$date = date($date_format, $new_timestamp);
//Set track not playing vars
$track = $track_data[1];
$text = $last_played_txt;
//Replace time/date/zone tags in text
$text = str_replace("<time>", $time, $text);
$text = str_replace("<date>", $date, $text);
$text = str_replace("<zone>", $zone, $text);
}
//The George Foreman lean mean (fat reducing) grilling machine stage
$track = trim($track);
$text = trim($text);
//Decode any HTML entities present in the track name
//(This function replicates html_entity_decode for
//compatibility with versions of php earlier than 4.3.0)
$translation_table = get_html_translation_table(HTML_ENTITIES);
$translation_table = array_flip($translation_table);
$track = strtr($track, $translation_table);
//Check to see if the track parse failed
if(!$track){
$text = $parse_error_text_line_1;
$track = $parse_error_text_line_2;
}
//Set the font
$font = realpath("./$font_filename");
//Get the text sizes
$top_bounds = imagettfbbox($font_size,0,$font,$text);
$bottom_bounds = imagettfbbox($font_size,0,$font,$track);
//Get the biggest text width (+10 spacing)
$max_width = max($top_bounds[4],$bottom_bounds[4])+10;
//Get the heights for the text fields
$top_height = ((0-$top_bounds[7])+$top_bounds[3]);
$bottom_height = ((0-$bottom_bounds[7])+$bottom_bounds[3]);
//Get the total text height (+10 spacing)
$max_height = $top_height+$bottom_height+10;
//Get the text placement heights
$top_placement_height = $top_height+40;
$bottom_placement_height = $top_height+$bottom_height+43;
//Generate the image canvas
$image = imagecreatefromjpeg('greenbg.jpg');
//Function to convert from hex colours
function imagecolorallocateHex($image,$hex){
if($hex[0]=="#"){
$hex_tail = substr($hex, 1);
}
$decimal = hexdec($hex_tail);
$alloc_colour = imagecolorallocate($image, ($decimal & 0xFF0000) >> 16,
($decimal & 0x00FF00) >> 8,
($decimal & 0x0000FF));
return $alloc_colour;
}
//Set the colours
$datecol = imagecolorallocateHex($image, $date_color);
$trackcol = imagecolorallocateHex($image, $track_color);
$bgcol = imagecolorallocateHex($image, $background_colour);
//Check if this image is to be transparent
if($transparent = true){
imageColorTransparent($image, $bgcol);
}
//Check to see if we want antialiasing
if($antialias == false){
$fgcol = "-$fgcol";
}
//Check to see if we want the top text right-aligned
if($top_align == "right"){
$top_align_px_offset = (500 - $top_bounds[4]) - 10;
}else{
$top_align_px_offset = 5;
}
//Check to see if we want the bottom text right-aligned
if($bottom_align == "right"){
$bottom_align_px_offset = (500 - $bottom_bounds[4]) - 10;
}else{
$bottom_align_px_offset = 5;
}
//Place the elements on the canvas
imagettftext($image, $font_size, 0, $top_align_px_offset, $top_placement_height, $datecol, $font, $text);
imagettftext($image, $font_size, 0, $bottom_align_px_offset, $bottom_placement_height, $trackcol, $font, $track);
//Output the image, checking what type has been requested
if($image_type == "jpg"){
imagejpeg($image, "sig-$safe_username.jpg");
}else{
imagepng($image, "sig-$safe_username.png");
}
//EXTERMINATE!
imagedestroy($image);
}
//Generate the header dates (Last modified + Expires)
$file_creation_time = filectime("./sig-$safe_username.$image_type");
$last_modified_date = gmdate("D, d M Y H:i:s",$file_creation_time);
$expires_date = gmdate("D, d M Y H:i:s",$file_creation_time + $update_period);
//Output the correct image type header
if ($image_type == "png"){
header("Content-type: image/png\n\n");
}elseif ($image_type == "jpg"){
header("Content-type: image/jpeg\n\n");
}
//Output the date headers
header("Last-Modified: $last_modified_date GMT\n\n");
header("Expires: $expires_date GMT\n\n");
//Pass through the image
readfile("./sig-$safe_username.$image_type");
?>
Here's what the image actually looks like:
http://www.strawberrymosquito.com/hosted/ryan/scrobblersig/sig-ryanprov.png
EDIT: When I actually tried to call the script it gave me a bunch of errors o_O I'm actually switching web hosts right now, so that may have something to do with it. In any case, that's the image it produces. The text is weird because I haven't been uploading data to my music profile lately.
Oh, and I'm moving this to the Programming Lexicon for you.
Sikawtic
03-28-2006, 11:23 PM
Thanks for all that :D
You r teh rox
~Phazanzar
vBulletin® v3.7.2, Copyright ©2000-2008, Jelsoft Enterprises Ltd.