Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Randomizing forum signatures.

Joined
Oct 11, 2007
Messages
1,706
Reaction score
517
Well, I was having a hard time picking a signature for my profile, then I thought, why not use all of them instead?

So, I present to you: My random signature ... thingie.

lol basically what it does is that it randomizes my signatures every time someone refreshes and displays a different one :).

(Example is in my signature).

If you want one then hit me up and I might make one for ya if I have some time over :), if a lot of people want this I might just make it an automated service (it's pretty easy so).


Here's the source code if anyone is interested, it's coded like crap since well, I made this script in what, 2 hours, parts of it are not written by me and parts are, (the functions in the end arent by me.)

The rest should be mine, not sure, old script lol.

Anyhow, as you can see you also need a table with the following columns: id, sig_refresh.

And that should be it lol.
PHP:
<?php	

$link = mysql_connect('ip', 'user', 'pw');
if (!$link) {
	 die('Could not connect to DATABASE: ' . mysql_error());
}
mysql_select_db('', $link);

/*
Coded by Justei (Kristoffer Blasiak)
For: RaGEZONE.com
*/

$q2 = mysql_query("UPDATE signature_fun SET sig_refresh = sig_refresh + 1 WHERE id = '1'")or die(mysql_error());
	
$q = mysql_query("SELECT * FROM signature_fun WHERE id = '1'")or die(mysql_error());
$r = mysql_fetch_row($q);

	$text = 'Justei random sigs ftw ^^'; 

	if(empty($text))
		fatal_error('Error: Text not properly formatted.') ;


	// customizable variables
	$font_file 	= "ambient.ttf";
	$font_size  	= 22 ; // font size in pts
	$font_size2 	= 11 ;
	$i = rand(1, 7);
	
	if($i == 1){
		$font_color 	= '#ffffff';
		$font_color2 	= '#ffffff' ;
	}
	
	if($i == 2){
		$font_color 	= '#000000';
		$font_color2 	= '#000000' ;
	}
	
	if($i == 3){
		$font_color 	= '#000000';
		$font_color2 	= '#000000' ;
	}
	
	if($i == 4){
		$font_color 	= '#ffffff';
		$font_color2 	= '#ffffff' ;
	}
	
	if($i == 5){
		$font_color 	= '#ffffff';
		$font_color2 	= '#ffffff' ;
	}
	
	if($i == 6){
		$font_color 	= '#ffffff';
		$font_color2 	= '#ffffff' ;
	}
	
	if($i == 7){
		$font_color 	= '#ffffff';
		$font_color2 	= '#ffffff' ;
	}
	
	$image_file 	= 'img/'.$i.'.png';

		

	// x and y for the bottom right of the text
	// so it expands like right aligned text
	$x_finalpos 	= 200;
	$y_finalpos 	= 30;
	

	
	// trust me for now...in PNG out PNG
	$mime_type 			= 'image/png' ;
	$extension 			= '.png' ;
	$s_end_buffer_size 	= 4096 ;



	// check for GD support
	if(!function_exists('ImageCreate'))
		fatal_error('Error: Server does not support PHP image generation') ;

	// check font availability;
	if(!is_readable($font_file)) {
		fatal_error('Error: The server is missing the specified font.') ;
	}

	// create and measure the text
	$font_rgb = hex_to_rgb($font_color) ;
	$font_rgb2 = hex_to_rgb($font_color2) ;
	$box = @ImageTTFBBox($font_size,0,$font_file,$text) ;

	$text_width = abs($box[2]-$box[0]);
	$text_height = abs($box[5]-$box[3]);
	

	$image =  imagecreatefrompng($image_file);

	if(!$image || !$box)
	{
		fatal_error('Error: The server could not create this image.') ;
	}

	// allocate colors and measure final text position
	$font_color = ImageColorAllocate($image,$font_rgb['red'],$font_rgb['green'],$font_rgb['blue']) ;
	$font_color2 = ImageColorAllocate($image,$font_rgb2['red'],$font_rgb2['green'],$font_rgb2['blue']) ;

	$image_width = imagesx($image);

	$put_text_x = $image_width - $text_width - ($image_width - $x_finalpos);
	$put_text_y = $y_finalpos;
	
	// Write the text
	$put_text_y2 = $y_finalpos + 18;
	$put_text_y3 = $y_finalpos + 40;
	
	$text2 = $r[1].' views of my sig ^^!';
	$text3 = 'Coded by: Justei @ RageZone.com';
	
	imagettftext($image, $font_size, 0, 10,  $put_text_y, $font_color, $font_file, $text);
	imagettftext($image, $font_size2, 0, 10,  $put_text_y2, $font_color2, $font_file, $text2);
	imagettftext($image, $font_size2, 0, 10,  $put_text_y3, $font_color2, $font_file, $text3);
	

	header('Content-type: ' . $mime_type) ;
	ImagePNG($image) ;

	ImageDestroy($image) ;
	exit ;


	function fatal_error($message)
	{

		// send an image
		if(function_exists('ImageCreate'))
		{
			$width = ImageFontWidth(5) * strlen($message) + 10 ;
			$height = ImageFontHeight(5) + 10 ;
			
			if($image = ImageCreate($width,$height))
			{
				$background = ImageColorAllocate($image,255,255,255) ;

				$text_color = ImageColorAllocate($image,0,0,0) ;
				ImageString($image,5,5,5,$message,$text_color) ;    

				header('Content-type: image/png') ;
				ImagePNG($image) ;
				ImageDestroy($image) ;
				exit ;
			}
		}

		// send 500 code
		header("HTTP/1.0 500 Internal Server Error") ;
		print($message) ;
		exit ;

	}
	
	/* 
		decode an HTML hex-code into an array of R,G, and B values.
		accepts these formats: (case insensitive) #ffffff, ffffff, #fff, fff 
	*/    

	function hex_to_rgb($hex) {

		// remove '#'

		if(substr($hex,0,1) == '#')

			$hex = substr($hex,1) ;

	

		// expand short form ('fff') color to long form ('ffffff')

		if(strlen($hex) == 3) {

			$hex = substr($hex,0,1) . substr($hex,0,1) .

				   substr($hex,1,1) . substr($hex,1,1) .

				   substr($hex,2,1) . substr($hex,2,1) ;

		}

	

		if(strlen($hex) != 6)

			fatal_error('Error: Invalid color "'.$hex.'"') ;

	

		// convert from hexidecimal number systems

		$rgb['red'] = hexdec(substr($hex,0,2)) ;

		$rgb['green'] = hexdec(substr($hex,2,2)) ;

		$rgb['blue'] = hexdec(substr($hex,4,2)) ;

	

		return $rgb ;

	}

?>

Add from alphakilo23:
Add:
PHP:
imagealphablending($image, true);
imagesavealpha($image, true);
after declaring the $image variable.
 
Last edited:
Canadian
Loyal Member
Joined
Dec 4, 2007
Messages
1,936
Reaction score
96
Very nice script, but how exactly do you use it on forums? I thought PHP and HTML was blocked?
 
Banned
Banned
Joined
Oct 20, 2006
Messages
3,245
Reaction score
1,652
@Mike: You use a simple Rewrite rule to change requests for the PNG/JPG to the PHP file, and the PHP file takes care of outputting the expected data stream (ie. an image).

I have something similar to this called "SigBawx" that a friend wrote. It allows people to submit messages that are displayed in someone else's signature, along with their name (like a chat box). I might fix it up and release the source here.
 
Joined
Oct 11, 2007
Messages
1,706
Reaction score
517
@Mike: You use a simple Rewrite rule to change requests for the PNG/JPG to the PHP file, and the PHP file takes care of outputting the expected data stream (ie. an image).

I have something similar to this called "SigBawx" that a friend wrote. It allows people to submit messages that are displayed in someone else's signature, along with their name (like a chat box). I might fix it up and release the source here.

Well, I don't really do it that way above, check out the php script, then I just do a <img src="link-to-my.php"/>

I host that in a .php file, then just use that to link in the src="" of a <img :p

Obviously I don't use the <img tag, but u can embed pics here in your sigs, so I just input my link there :)
 
Last edited:
Joined
Jun 27, 2010
Messages
411
Reaction score
240
It replaces the PNG transparency with black, is there a workaround for that?
Disregard that, I suck at googling, here's the fix:

Add:
PHP:
imagealphablending($image, true);
imagesavealpha($image, true);
after declaring the $image variable.

Source:
 
Last edited:
Joined
Oct 11, 2007
Messages
1,706
Reaction score
517
It replaces the PNG transparency with black, is there a workaround for that?
Disregard that, I suck at googling, here's the fix:

Add:
PHP:
imagealphablending($image, true);
imagesavealpha($image, true);
after declaring the $image variable.

Source:

Added to first post :) didn't need alpha channel so didn't even care about it ^^ but useful for some people!
 
Infraction Baɴɴed
Loyal Member
Joined
Apr 9, 2008
Messages
1,416
Reaction score
169
question?

is this your first attempt at the GD library?

EDIT:
sorry couldnt resist
PHP:
<?php
/*
Coded by Justei (Kristoffer Blasiak)
EDITED BY: Holthelper
For: RaGEZONE.com
*/

// trust me for now...in PNG out PNG
$mime_type = IMAGETYPE_PNG;

// customizable variables
$font_file  = "ambient.ttf";
$font_size  = 22 ;
$font_size2 = 11 ;
$image_inc  = rand(1, 7);
$image_src = 'img/'.$image_inc.'.png';

// x and y for the bottom right of the text
$x_pos = 200;
$y_pos = 30;

if(!$image = @imagecreatefrompng($image_src)) {
	fatal_error('Error: The server could not create this image.') ;
}

if(!$link = mysql_connect('localhost', 'root', '')) {
	die('Could not connect to DATABASE: ' . mysql_error());
}
mysql_select_db('', $link);

function fatal_error($message) {
	// send an image
	if(function_exists('ImageCreate')) {
		$width = ImageFontWidth(5) * strlen($message) + 10 ;
		if($image = ImageCreate($width, 25)) {
			$background = ImageColorAllocate($image,255,255,255) ;
			$text_color = ImageColorAllocate($image,0,0,0);
			ImageString($image,5,5,5,$message,$text_color);    

			header('Content-type: image/png');
			ImagePNG($image);
			ImageDestroy($image);
			exit;
		}
	}
	header("HTTP/1.0 500 Internal Server Error") ;
	print($message) ;
	exit;
}

function hex_to_rgb($hex) {
	$rgb['red']   = hexdec(substr($hex,1,2));
	$rgb['green'] = hexdec(substr($hex,3,2));
	$rgb['blue']  = hexdec(substr($hex,5,2));
	return $rgb;
}


mysql_query("UPDATE `signature_fun` SET `sig_refresh` = sig_refresh + 1 WHERE `id` = '1'") or die(mysql_error());
$r = mysql_fetch_row(mysql_query("SELECT `sig_refresh` FROM `signature_fun` WHERE `id` = '1'"));

switch($image_inc) {
	case 1:
	case 4:
	case 5:
	case 6:
	case 7:
		$font_color  = '#ffffff';
	break;
	case 2:
	case 3:
		$font_color  = '#000000';
	break;
}

// Text
$title = 'Justei random sigs ftw ^^';
$view = $r[0].' views of my sig ^^!';
$cred = 'Coded by: Justei @ RageZone.com';

// Text Color
$RGB = hex_to_rgb($font_color);

// check font availability;
if(!is_readable($font_file)) {
	fatal_error('Error: The server is missing the specified font.') ;
}

// allocate colors and measure final text position
$font_color = ImageColorAllocate($image, $RGB['red'], $RGB['green'], $RGB['blue']) ;

imagettftext($image, $font_size,  0, 10,  $y_pos, $font_color, $font_file, $title);
imagettftext($image, $font_size2, 0, 10,  $y_pos + 18, $font_color, $font_file, $view);
imagettftext($image, $font_size2, 0, 10,  $y_pos + 40, $font_color, $font_file, $cred);

header('Content-type: '.Image_Type_To_Mime_Type($mime_type));
ImagePNG($image);
ImageDestroy($image);
?>
SQL:
Code:
DROP TABLE IF EXISTS `signature_fun`;
CREATE TABLE  `signature_fun` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `sig_refresh` int(13) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
Last edited:
Joined
Oct 11, 2007
Messages
1,706
Reaction score
517
Holthelper: well I never needed it before so never had to use it :p so yes this is the first time i use it, I know its messy, thats cus i took this directly from another project I had made :) made it in like 2h so :p

And, so basically what you did was reorganize my code, clean it up, and made a switch case, okay. Anyhow.
 
Last edited:
Banned
Banned
Joined
Oct 20, 2006
Messages
3,245
Reaction score
1,652
@hotlhelper: Instead of coming here, asking if this is the first time someone has used a certain library before (that is a blatant underlying insult), then posting modified code and claiming that you "couldn't resist" (pretty smug, don't you think?), how about you point things out and GENUINELY try to help, without acting like you're better and trying to insinuate that Justei is somehow of lesser intelligence?
 
Infraction Baɴɴed
Loyal Member
Joined
Apr 9, 2008
Messages
1,416
Reaction score
169
im not insulting him at all, i know he can code better then that. so when i saw this messy code i had to clean it.

idk about you but i have sorta OCD so it just bugged the sh*t out of me that it was really messy and redundant.

ive been messing with the GD library from some time now as you can tell from my sig
 
█║▌║▌║TheMerc iful║▌║▌║█
Loyal Member
Joined
Jan 29, 2005
Messages
1,367
Reaction score
80
Damn! Yamachi!!!

I Just Saw Your Siggy... And Boy Do i LOL'd Too Much!!! :junglejane:

Sorry, For The Off Topic! But Thanks For This Randmizing Sig. That i Just Saw...
 
Back
Top