Merging 2 scripts

Well, you can change the FONT SIZE easily. It is pulled from the SigX site. You just log into your account and set the size of the font used along with the color. These are pulled from my PHP script and adjusted when written over the images. There are five sizes (1 to 5) for these and they are the general “latin” characters. (In five sizes) You can use TrueType fonts if they are available for all your users. So, you could use most of the current standard ones. These have to be coded in a different way.

Let me know if you mean just your own size fonts or TrueType ones.

*** ALSO, I found one small error in my code, you must change this line:

    imagestring ($background, $fontsize, $avatar_x + 10, ImageFontHeight($font) * $x + 40,  $textdata[$x], $fontColor);

TO THIS VERSION: (Note $font should be $fontsize)
imagestring ($background, $fontsize, $avatar_x + 10, ImageFontHeight($fontsize) * $x + 40, $textdata[$x], $fontColor);

Okay, I just figured out that to use TrueType fonts, you have to use a different PHP command.
You have to change the imagestring commands and use an ImageTTFText…

The problem is that this command has to know where the TrueType font is located to point the code to it.
TrueType fonts are not always in the same place on a user’s computer… If your signature is always seen
by all users on YOUR site, then, we can figure out a routine to do this. We would have to know where
the TrueType font is located, or, even better, create a copy of it on your server which could be loaded into
the display page… Let me know what font you want to use…

oh you can use comic.ttf as the name

Okay, get it loaded onto your site in the same folder that the display page is. I will send you the code in a moment…

Well, it looks like you just use this code:
(Replace what you have for this section…)
[php]
// Draw text from SigX onto PNG graphic (Using offset for avatar, max lines, font colors)
if( is_array($textdata) ){ // Y-offset is below your heading ( 40 for now)
for($x = 0; $x< count($textdata); $x++){ // In next line X-offset is Avatar’s width + 10
imagettftext ($background, $fontsize, 0, $avatar_x + 10, ImageFontHeight($fontsize) * $x + 40, $fontColor, “comic.ttf”, $textdata[$x]);
}
} else {
imagettftext ($background, $fontsize, 0, $avatar_x + 10, 40, $fontColor, “comic.ttf”, $textdata[$x]);
}
[/php]
Leaving for a few hours… Let me know if you have problems with it…

I fully understand that, the data originates from karanina and is sent to sigx for the image building of sigx, however her friend made a script to build a customize image instead, and so she is using it with the data being retrieved from sigx. My suggestion is to cut SigX from this cutting out the middle man. So instead of sending the data to sigx, she can send it directly to her server instead. which would incread performance, since it no longer needs to retrieve data from sigx itself.

So the question is how is data being sent to sigx, so it can be changed to her server, and a small script to store the data and create an image & possibly a cache for the images.

well sigx is a program you install on your comp so i assume that’s what they use to get the data

It works perfectly Ernie! just 1 more thing!
there’s 1 line that seems to be buggy on the sig

on the sigx there a function that let’s users view their ip, isp operating system, url and browser, but in the sig i made only the variables appear (Hey, your ip is [user_ip] and ISP is [user_isp], or Your Browser is [user_browser] or You are running [user_os]. or You are browsing [ref]). Anyway to fix this

here’s the working image just in case
http://karanina.net/sigxO.php

LOL, if it is working PERFECTLY, there would not be 1 more thing… LOL…
(By the way, there is ALWAYS, 1 more thing… ) :wink:

Laffin, yes, I understand the not-using-SigX and doing it directly. I had mentioned that once at the start of this project. But, the problem is that SigX already has plugin’s for all the various items that are displayed, such as Itunes, WinAmp, MediaPlayer and a TON of others… These would take a TON of programming to duplicate and set up a local program to access… More programming than Karanina can handle at this point.
But, I agree it would be nice to control it yourself…

Karanina, It appears you are not receiving the info incorrectly from the SigX server. I will have to do some experiments to see what is going on… But, first, the local client (SigX program you installed on your system) has some options on what it sends. I think you have to set these on THEIR server side. You should log in and look at the data you are send out. It looks like you are sending the viewing info twice. (At least it is displayed twice.) Try removing the extra one. Also, you might try removing the reference to “You are browsing…” and then add it back in. I have found just removing/reloading will sometimes fix an online system like this. Let me know if these help… Looking good!

Ernie thank you so much for the help! the script worked perfectly you are a life saver!

A few days ago, my sis found a cd which had a copy of the script my friend gave me, and though i’m using yours, just wanted to leave here the one he used, just in case.

[php]<?
// SigX Remote Image Generater (Basic Background)
// Version 1.1,
// Notes: you can use any image, JPG PNG or GIF (gif untested), any size and dimention. just make sure its big enough to fit your biggest text
// this code does not resize the background image.
// my email: [email protected]

// Settings, Edit
// This is the only part you need to edit.
// number of different background images
$maxnum = 2;
//background image for random image script (has to be png)
$r_backgroundurl=“name of background.png”;

// Username Setting
$un = “sigxusername”;

// where the text goes on the image, offset to blank area on the image, in pixels.
$Xoffset=0;
$Yoffset=0;

////////////////////////////////////////////////////
// No need to go further.
///////////////////////////////////////////////////
// Code, Only edit if you know what you are doing!!
//////////////////////////////////////////////////

$alldata = getSomeData($un); // We get signal. It is you. How are you gentleman? Make your time now.

if (empty($alldata)) { die(“cant contact server to get any data”); }

$fc = $fc = “255,255,255”;//GetMid($alldata,"<fc="," \fc>"); // font color
$bc = GetMid($alldata,"<bc="," \bc>"); // background color (not used if background image set)
$fz = 1; //GetMid($alldata,"<fz="," \fz>"); // font size
$trans = GetMid($alldata,"<trans="," \trans>"); // the \t so we can type letter t. if background image is not set (transparencys not work if using imagecreatetruecolor() which i am.)
$data = GetMid($alldata,"<data="," \data>"); // the data from sigx.yuriy.net server, what we got to work with.

//<fc=0,0,0 \fc>
//<bc=0,0,0 \bc>
//<fz= 1 \fz>
//<trans=0 \trans>
//<data=Visit http://sigx.yuriy.net \data>

if( $data ){ // if we get the data ok
drawIt($data, $fc, $bc, $fz, $trans, $Xoffset, $Yoffset, $backIMG);
//echo “$data, $fc, $bc, $fz, $trans, $backIMG”;
}

//
////
// cool functions
////

function drawIt($data, $fontcolor=“255,255,255”, $backcolor=“255,255,255”, $font=“2”, $transperancy=1, $Xoffset=3, $Yoffset=3, $backIMG=’’){
global $r_backgroundurl, $maxnum;

// max amount of lines
$maxElements = 10;

if( $data ) {
	// if we pass our data dynamic array string
	$data = explode("*<*",$data);
}

#creating bkIMG on the fly instead of opening it from an url
$background = imagecreatefrompng($r_backgroundurl);
$curimageid = rand(1,$maxnum);

$curimagepath = “pic” . $curimageid . “.png”;
$insert = imagecreatefrompng($curimagepath);

imagecolortransparent($insert,imagecolorat($insert,0,0));

$insert_x = imagesx($insert);
$insert_y = imagesy($insert);

imagecopymerge($background,$insert,0,0,0,0,$insert_x,$insert_y,100);

$bkIMG=$background;
$bkIMG_width=imagesx($bkIMG);  // get width and height of the background image
$bkIMG_height=imagesy($bkIMG); 		
// we set the width and height based on the background image provided.
$width = $bkIMG_width; 
$height = $bkIMG_height; 
/*if ( file_exists($backIMG) ){

	# reading image
	$image = @getImageSize($backIMG, $info); # $info, only to handle problems with earlier php versions...
	switch($image[2]) {
	case 1:
		# GIF image
		$bkIMG = @imageCreateFromGIF($backIMG);
		break;
	case 2:
		# JPEG image
		$bkIMG = @imageCreateFromJPEG($backIMG);
		break;
	case 3:
		# PNG image
		$bkIMG = @imageCreateFromPNG($backIMG);
		break;
	default:
		# PNG
		$bkIMG = @imageCreateFromPNG($backIMG);
		break;
	}

	//$bkIMG = @imageCreateFromPNG($backIMG); // create the background image from a PNG file
	$bkIMG_width=imageSX($bkIMG);  // get width and height of the background image
	$bkIMG_height=imageSY($bkIMG); 		
	// we set the width and height based on the background image provided.
	$width = $bkIMG_width; 
	$height = $bkIMG_height;
}*/

if ( !$bkIMG ) { // if no background image is set
	if( is_array($data) ){ // if we have the data

		$data = array_slice($data, 0, $maxElements); // cut off the limitation of lines

		for($x = 0; $x <= count($data); $x++){ // find the widest line, and we have our width
			$curWidth =  ImageFontWidth($font) * strlen($data[$x]) + $Xoffset+2;
			if($curWidth > $defaultWidth){
				$defaultWidth = $curWidth;
			}
		}
		if($defaultWidth > 500) { $defaultWidth = 500; }	
		$width  = $defaultWidth;

		// lets do the same for height
		$curHeight = ImageFontHeight($font) * count($data) + $Yoffset + 2;		

		if ($curHeight > $defaultHeight){ $defaultHeight = $curHeight; }
		$height = $defaultHeight;		

	} else { // if its just an offline msg or single element

		$curWidth =  ImageFontWidth($font) * strlen($data) + $Xoffset+2;

		if($curWidth > $defaultWidth){
			$defaultWidth = $curWidth;
		}

		if($defaultWidth > 500) { $defaultWidth = 500; }
		$width  = $defaultWidth;

		$curHeight = ImageFontHeight($font) + $Yoffset+2;			
		if ($curHeight > $defaultHeight){ 
			$defaultHeight = $curHeight; 
		}

		$height = $defaultHeight;
	}
}


$im = @imagecreatetruecolor ($width,$height); // create the image

$fColor = explode(",",$fontcolor); // font color
$bColor = explode(",",$backcolor); // back color

$bgc = imagecolorallocate ($im, $bColor[0], $bColor[1], $bColor[2]); // default white
imagefilledrectangle($im, 0, 0, $width, $height, $bgc);

//mergePix(&$sourcefile, $insertfile, $pos=1,$transition=100) 
if ($bkIMG){ // if we found a background image
	@mergePix($im, $bkIMG, 1); // put our background image on top left
}

// if transperent (....)
// note: if using imagecreatetruecolor transperancy is not working. but if your using a img it makes no difference
//if ( $transperancy == 1) { // only used if no backgrouns image set, only works for PNG, maybe GIF
	//ImageColorTransparent($im, $bgc);
//}


// lets allocate some colors
$fontColor = imagecolorallocate ($im, $fColor[0], $fColor[1], $fColor[2]);
$black = imagecolorallocate ($im, 0, 0, 0);

if( is_array($data) ){
// start outputing the info, line by line
	for($x = 0; $x< count($data); $x++){
	imagettftext ($im, 10, 0, $Xoffset, (ImageFontHeight($font) +5) * $x + $Yoffset+5, $fontColor, realpath("kara.ttf"), $data[$x]);
	}
} else {
	imagettftext ($im, 10, 0, $Xoffset, ImageFontHeight($font) * $x + $Yoffset, $fontColor, realpath("kara.ttf"), $data);
}


# output
switch($image[2]) {
	case 1:
	# GIF image
	header("Content-type: image/gif");
	imageGIF($im);
	break;
case 2:
	# JPEG image
	header("Content-type: image/jpeg");
	imageJPEG($im);
	break;
case 3:
	# PNG image
	header("Content-type: image/png");
	imagePNG($im);
	break;
default:
	# PNG image
	header("Content-type: image/png");
	imagePNG($im);
	break;
}

# cleaning cache
imageDestroy($im);	
imageDestroy($bkIMG);

}

// Functions, belong to their respective owners.
function ImageStringWrap($image, $font, $x, $y, $text, $color, $maxwidth)
{
$fontwidth = ImageFontWidth($font);
$fontheight = ImageFontHeight($font);

if ($maxwidth != NULL) {
$maxcharsperline = floor($maxwidth / $fontwidth);
$text = wordwrap($text, $maxcharsperline, “\n”, 1);
}

$lines = explode("\n", $text);
while (list($numl, $line) = each($lines)) {
ImageString($image, $font, $x, $y, $line, $color);
$y += $fontheight;
}
}

// Align string on image
// $x and $y values
// 0 align left or top
// 1 align center
// 2 align right or bottom
function ImageStringAlign(&$image, $font, $x, $y, $s, $col) {
switch ($x) {
case 0: $x = 2; break;
case 1: $x = floor((ImageSX($image) / 2) - ((ImageFontWidth($font) * strlen($s)) / 2)); break;
case 2: $x = (ImageSX($image) - (ImageFontWidth($font) * strlen($s))) - 2; break;
}
switch ($y) {
case 0: $y = 2; break;
case 1: $y = floor((ImageSY($image) / 2) - (ImageFontHeight($font) / 2)); break;
case 2: $y = (ImageSY($image) - ImageFontHeight($font)); break;
}
ImageString($image, $font, $x, $y, $s, $col);
}

function getSomeData($username=""){
// this allows us to get the remote data

$alldata = '';
$username = urlencode($username); // encode in case name has spaces

$fd=fopen("http://sigx.yuriy.net/remote/textout.php?username=$username","r");
while ($line=fgets($fd,1000))
{
 	$alldata.=$line;
}
fclose ($fd);
return $alldata;

}

function GetMid($TheStr, $sLeft, $sRight){

$pleft = strpos($TheStr, $sLeft, 0);	
if ($pleft !== false){
	$pright = strpos($TheStr, $sRight, $pleft + strlen($sLeft));			
	If ($pright !== false) {
		return (substr($TheStr, $pleft + strlen($sLeft), ($pright - ($pleft + strlen($sLeft)))));
	}
}
return '';

}

//$sourcefile = Filename of the picture into that $insertfile will be inserted.
//$insertfile = Filename of the picture that is to be inserted into $sourcefile.
//$targetfile = Filename of the modified picture.
//$transition = Intensity of the transition (in percent)
//$pos = Position where $insertfile will be inserted in $sourcefile
// 0 = middle
// 1 = top left
// 2 = top right
// 3 = bottom right
// 4 = bottom left
// 5 = top middle
// 6 = middle right
// 7 = bottom middle
// 8 = middle left
//
//
function mergePix(&$sourcefile, &$insertfile, $pos=1,$transition=100)
{

//Get the resource id´s of the pictures
//$insertfile_id = imageCreateFromPNG($insertfile);
//$sourcefile_id = imageCreateFromPNG($sourcefile);
$insertfile_id = $insertfile;
$sourcefile_id = $sourcefile;

//Get the sizes of both pix
$sourcefile_width=imageSX($sourcefile_id);
$sourcefile_height=imageSY($sourcefile_id);
$insertfile_width=imageSX($insertfile_id);
$insertfile_height=imageSY($insertfile_id);

//middle
if( $pos == 0 )
{
$dest_x = ( $sourcefile_width / 2 ) - ( $insertfile_width / 2 );
$dest_y = ( $sourcefile_height / 2 ) - ( $insertfile_height / 2 );
}

//top left
if( $pos == 1 )
{
$dest_x = 0;
$dest_y = 0;
}

//top right
if( $pos == 2 )
{
$dest_x = $sourcefile_width - $insertfile_width;
$dest_y = 0;
}

//bottom right
if( $pos == 3 )
{
$dest_x = $sourcefile_width - $insertfile_width;
$dest_y = $sourcefile_height - $insertfile_height;
}

//bottom left
if( $pos == 4 )
{
$dest_x = 0;
$dest_y = $sourcefile_height - $insertfile_height;
}

//top middle
if( $pos == 5 )
{
$dest_x = ( ( $sourcefile_width - $insertfile_width ) / 2 );
$dest_y = 0;
}

//middle right
if( $pos == 6 )
{
$dest_x = $sourcefile_width - $insertfile_width;
$dest_y = ( $sourcefile_height / 2 ) - ( $insertfile_height / 2 );
}

//bottom middle
if( $pos == 7 )
{
$dest_x = ( ( $sourcefile_width - $insertfile_width ) / 2 );
$dest_y = $sourcefile_height - $insertfile_height;
}

//middle left
if( $pos == 8 )
{
$dest_x = 0;
$dest_y = ( $sourcefile_height / 2 ) - ( $insertfile_height / 2 );
}

//The main thing : merge the two pix
imageCopyMerge($sourcefile_id, $insertfile_id,$dest_x,$dest_y,0,0,$insertfile_width,$insertfile_height,$transition);

return $sourcefile_id;
}

?>[/php]

Anyway I’m going to mark this topic as solved. Thank you so much for the help! i’m very pleased!

Thank you! Glad we could help you…

Thanks for listing the old code, it might help someone else. My version was streamlined for your use.
It did not have options to place avatar’s in various places. I did not think you need this as your full
background image was not very large. I could see where someone might want a larger banner across
their entire page and may need more routines. But, my version is quick and seems to work well…

Congrats on finishing your project…

Sponsor our Newsletter | Privacy Policy | Terms of Service