Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A couple of problems with a script, please help.

Status
Not open for further replies.

Monochrome

Technical User
Oct 27, 2005
13
US
I'm using this script, which should be working fine, but the person that made the script said he'd give no support, so that's why i'm here, i'm having a couple of problems. I have no real php experiance you see.

<?php

/* check the referer header */
$ref = strtolower(getenv("HTTP_REFERER"));
$pos = (substr($ref, 0, 33) == " ? 1 : 0);
$pos += (substr($ref, 0, 29) == " ? 1 : 0);
$pos += (substr($ref, 0, 20) == " ? 1 : 0);

/* if the referer is from an external host, throw an error and quit */
if ($ref && !$pos) {
echo "Sorry, no remote linking.";
exit;
}

/* get the text for each line from the query string, convert it to upper case,
and truncate it to 20 characters */

$line[1] = substr(strtoupper(stripslashes($_GET['line1'])),0,20);
$line[2] = substr(strtoupper(stripslashes($_GET['line2'])),0,20);
$line[3] = substr(strtoupper(stripslashes($_GET['line3'])),0,20);
$line[4] = substr(strtoupper(stripslashes($_GET['line4'])),0,20);

/* This is the list of allowed characters. The reason more characters aren't allowed is
because I didn't put more characters in the characters image. More characters means
more figuring out coordinates, ie. more work. Each character array comprises the character
itself, its X coordinate (the Y coordinate is always 0), and its width (the height is always
12, the height of the image). */

$allowed_chars = array(
array("A", 0, 11),
array("B", 11, 10),
array("C", 21, 10),
array("D", 31, 10),
array("E", 41, 10),
array("F", 51, 9),
array("G", 60, 11),
array("H", 71, 10),
array("I", 81, 5),
array("J", 86, 9),
array("K", 95, 11),
array("L", 106, 9),
array("M", 115, 11),
array("N", 126, 10),
array("O", 136, 11),
array("P", 147, 10),
array("Q", 157, 11),
array("R", 168, 10),
array("S", 178, 9),
array("T", 187, 10),
array("U", 197, 9),
array("V", 206, 10),
array("W", 216, 13),
array("X", 229, 9),
array("Y", 238, 10),
array("Z", 248, 9),
array("0", 257, 9),
array("1", 266, 8),
array("2", 274, 9),
array("3", 283, 8),
array("4", 291, 9),
array("5", 300, 8),
array("6", 308, 9),
array("7", 317, 9),
array("8", 326, 8),
array("9", 334, 9),
array(",", 343, 6),
array(".", 349, 5),
array("?", 354, 10),
array("!", 364, 5),
array("-", 369, 7),
array("+", 376, 8),
array("=", 384, 9),
array("/", 393, 6),
array("'", 399, 5),
array("$", 404, 8),
array(":", 413, 4),
array("&", 417, 9)
);

/* load the characters image and the background sign image into memory */

$chars_img = imagecreatefromgif("../images/csg/chars1.gif");
$basesign_img = imagecreatefromjpeg("../images/csg/basesign.jpg");

/* get the width and height of the background image */

$src_w = imagesx($basesign_img);
$src_h = imagesy($basesign_img);

/* create a new image, that will be output to the browser */

$output_img = imagecreatetruecolor($src_w, $src_h);

/* copy the background image onto the output image */

imagecopy($output_img, $basesign_img, 0,0,0,0, $src_w, $src_h);

/* Since the letters are centered on the sign, the x centerpoint gives a starting point from
which the x offset for each letter can be calculated. The y offset is simply the distance
from the top of the image to the top of the first row of letters. */

$x_center = 175;
$y_offset = 145;

/* This first pass is to calculate the x offset for each row, since the width of the
line of characters is different for each row for each sign. It loops through the letters
of each row and adds the width of each letter to the x centerpoint to get the beginning
point for each line. */

foreach($line as $thisline) {
$x_offset = 0;

// calculate offset
for ($i = 0; $i < strlen($thisline); $i++) {
/* Get the current character from the current line */
$curchar = substr($thisline, $i, 1);

/* A space character is given an arbitrary width of 3 pixels; there isn't a space character
in the characters image. */
if ($curchar == " ") {
$x_offset += 3;
} else {
/* loop through the characters array until we reach the one matching the current
character, and add half its width to the x offset. */
foreach($allowed_chars as $char) {
if ($curchar == $char[0]) {
$x_offset += ceil($char[2] / 2);
}
}
}
}

/* The second pass actually copies each letter from the characters image onto the output image. */

for ($i = 0; $i < strlen($thisline); $i++) {
$curchar = substr($thisline, $i, 1);
if ($curchar == " ") {
$x_offset -= 6;
} else {
foreach($allowed_chars as $char) {
if ($curchar == $char[0]) {
/* The imagecopymerge() function copies a rectangular area from one image onto another image.
This is documented more than adequately on php.net. */
imagecopymerge($output_img, $chars_img, $x_center - $x_offset, $y_offset, $char[1],
0, $char[2], 12, 100);
$x_offset -= $char[2];
}
}
}
}

/* When each row is complete, add 16 pixels to the Y offset to get the top of the new row. */
$y_offset += 16;
}

/* Now that the image is built, it gets sent to the browser. First, send out HTTP headers to
tell the browser a JPEG image is coming. */
header("Content-Type: image/jpeg");
header("Content-Disposition: inline; filename=churchsign.jpg");

/* The imagejpeg() function sends the output img to the browser. */
imagejpeg($output_img);

/* Housekeeping functions - destroy the scratch images to free up the memory they take up. */
imagedestroy($basesign_img);
imagedestroy($chars_img);
imagedestroy($output_img);

?>


First off, the 3 parts at the top with the websites and ip address code in, i guess are just so that if the website it's parsed through isn't them, it will say, sorry no remote linking, i changed them to my sites name, which is theweenie.t35.com and it kept saying 'Sorry, no remote linking'

So, i got sick of it, and removed it to check if the script would work at all. Then it said a fatal error, undefined function imagecreatefromgif

Was that an error in the script? Or t35 not being able to use imagecreatfromgif. I tried to google that one, but nothing came up apart from a couple of people blamin' their servers.

Thanks in advance,
Monochrome.
 
Check that you have GD set up on your php installation I guess. That error implies to me that php just doesn't know about it... which leads me to think that it hasn't been installed.

You can see for yourself... create a file containing just this in it:
Code:
<? phpinfo() ?>

Look to see if GD is installed.

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
I did that, and it turned out that t35.com did not support GD. So i am now using the host tripod.co.uk, which supports it, although i had to change the imagefromgif, to imagefrompng. Now the script isn't working at all, here's the webpage code. Including all the html tags. Please could you tell me what's up with it?
The page is
Code:
<HTML>
<HEAD>
</HEAD>

<BODY>

<?php 

/* get the text for each line from the query string, convert it to upper case, 
and truncate it to 20 characters */ 

$line[1] = substr(strtoupper(stripslashes($_GET['line1'])),0,20); 
$line[2] = substr(strtoupper(stripslashes($_GET['line2'])),0,20); 
$line[3] = substr(strtoupper(stripslashes($_GET['line3'])),0,20); 
$line[4] = substr(strtoupper(stripslashes($_GET['line4'])),0,20); 

/* This is the list of allowed characters. The reason more characters aren't allowed is 
because I didn't put more characters in the characters image. More characters means 
more figuring out coordinates, ie. more work. Each character array comprises the character 
itself, its X coordinate (the Y coordinate is always 0), and its width (the height is always 
12, the height of the image). */ 

$allowed_chars = array( 
    array("A",   0, 11), 
    array("B",  11, 10), 
    array("C",  21, 10), 
    array("D",  31, 10), 
    array("E",  41, 10), 
    array("F",  51,  9), 
    array("G",  60, 11), 
    array("H",  71, 10), 
    array("I",  81,  5), 
    array("J",  86,  9), 
    array("K",  95, 11), 
    array("L", 106,  9), 
    array("M", 115, 11), 
    array("N", 126, 10), 
    array("O", 136, 11), 
    array("P", 147, 10), 
    array("Q", 157, 11), 
    array("R", 168, 10), 
    array("S", 178,  9), 
    array("T", 187, 10), 
    array("U", 197,  9), 
    array("V", 206, 10), 
    array("W", 216, 13), 
    array("X", 229,  9), 
    array("Y", 238, 10), 
    array("Z", 248,  9), 
    array("0", 257,  9), 
    array("1", 266,  8), 
    array("2", 274,  9), 
    array("3", 283,  8), 
    array("4", 291,  9), 
    array("5", 300,  8), 
    array("6", 308,  9), 
    array("7", 317,  9), 
    array("8", 326,  8), 
    array("9", 334,  9), 
    array(",", 343,  6), 
    array(".", 349,  5), 
    array("?", 354, 10), 
    array("!", 364,  5), 
    array("-", 369,  7), 
    array("+", 376,  8), 
    array("=", 384,  9), 
    array("/", 393,  6), 
    array("'", 399,  5), 
    array("$", 404,  8), 
    array(":", 413,  4), 
    array("&", 417,  9) 
); 

/* load the characters image and the background sign image into memory */ 

$chars_img = imagecreatefrompng("../images/chars1.png"); 
$basesign_img = imagecreatefromjpeg("../images/basesign.jpg"); 

/* get the width and height of the background image */ 

$src_w = imagesx($basesign_img); 
$src_h = imagesy($basesign_img); 

/* create a new image, that will be output to the browser */ 

$output_img = imagecreatetruecolor($src_w, $src_h); 

/* copy the background image onto the output image */ 

imagecopy($output_img, $basesign_img, 0,0,0,0, $src_w, $src_h); 

/* Since the letters are centered on the sign, the x centerpoint gives a starting point from 
which the x offset for each letter can be calculated. The y offset is simply the distance 
from the top of the image to the top of the first row of letters. */ 

$x_center = 175; 
$y_offset = 145; 

/* This first pass is to calculate the x offset for each row, since the width of the 
line of characters is different for each row for each sign. It loops through the letters 
of each row and adds the width of each letter to the x centerpoint to get the beginning 
point for each line. */ 

foreach($line as $thisline) { 
    $x_offset = 0; 

    // calculate offset 
    for ($i = 0; $i < strlen($thisline); $i++) { 
/* Get the current character from the current line */ 
        $curchar = substr($thisline, $i, 1); 

/* A space character is given an arbitrary width of 3 pixels; there isn't a space character 
in the characters image. */ 
        if ($curchar == " ") { 
            $x_offset += 3; 
        } else { 
/* loop through the characters array until we reach the one matching the current 
character, and add half its width to the x offset. */ 
            foreach($allowed_chars as $char) { 
                if ($curchar == $char[0]) { 
                    $x_offset += ceil($char[2] / 2); 
                } 
            } 
        } 
    } 

/* The second pass actually copies each letter from the characters image onto the output image. */ 

    for ($i = 0; $i < strlen($thisline); $i++) { 
        $curchar = substr($thisline, $i, 1); 
        if ($curchar == " ") { 
            $x_offset -= 6; 
        } else { 
            foreach($allowed_chars as $char) { 
                if ($curchar == $char[0]) { 
/* The imagecopymerge() function copies a rectangular area from one image onto another image. 
This is documented more than adequately on php.net. */ 
                    imagecopymerge($output_img, $chars_img, $x_center - $x_offset, $y_offset, $char[1], 
                        0,  $char[2], 12, 100); 
                    $x_offset -= $char[2]; 
                } 
            } 
        } 
    } 

/* When each row is complete, add 16 pixels to the Y offset to get the top of the new row. */ 
    $y_offset += 16; 
} 

/* Now that the image is built, it gets sent to the browser. First, send out HTTP headers to 
tell the browser a JPEG image is coming. */ 
header("Content-Type: image/jpeg"); 
header("Content-Disposition: inline; filename=churchsign.jpg"); 

/* The imagejpeg() function sends the output img to the browser. */ 
imagejpeg($output_img); 

/* Housekeeping functions - destroy the scratch images to free up the memory they take up. */ 
imagedestroy($basesign_img); 
imagedestroy($chars_img); 
imagedestroy($output_img); 

?>


		<!-- content -->

<h3>Make your sign</h3>

<table width="640" align="center">
<tr>
<td>
	<center><img src="churchsign.jpg" width="313" height="232"></center>
	<p>Make your very own church sign, kinda like the ones you see <a target="_top" href="churchsigns.php">here</a>. Just enter some text and click the 'Go' button. <a target="_top" href="index.php">Or pick another design</a>.</p>
</td>
</tr>
</table>

<script language="Javascript">
function checkform(frm) {
	if (frm.line1.value.length < 1 && frm.line2.value.length < 1 && frm.line3.value.length < 1 && frm.line4.value.length < 1) {
		alert ("Please enter some text.");
		frm.line1.focus();
		return false;
	}
}
</script>

<table width="640" border="0" align="center">
<form action="[URL unfurl="true"]http://members.lycos.co.uk/weenie1234/index.php"[/URL] method="post" onSubmit="return checkform(this)">
<tr>
<td width="40%">
line 1: <input type="text" name="line1" maxlength="22" value=""><br>
line 2: <input type="text" name="line2" maxlength="22" value=""><br>
line 3: <input type="text" name="line3" maxlength="22" value=""><br>
line 4: <input type="text" name="line4" maxlength="22" value=""><br>
<input type="submit" name="go" value="Go">
</td>
<td width="60%">
<p style="font-family: sans-serif; font-size: 11px;">(<B style="color: blue; background-color: yellow;">Note: do not link directly to the image generated on this site - it won't work.</B> You are free to download the image, copy it, put it on your own website, or distribute it however you like. If you don't have a website to store it on, there are plenty of <A TARGET="_blank" HREF="[URL unfurl="true"]http://www.google.com/search?q=free+image+hosting">free[/URL] image hosting</A> sites available.)</p>
</td>
</tr>
</form>
</table>

		<!-- /content -->

		

		</td>
		<td align="right">

		
		</td>
	</tr>
</table

</BODY>
</HTML>


is the original site.
also uses this source code, and got it to work. If that's any help.

Thanks in advance,
Monochrome.
 
I'm very sorry, the content part is wrong from what's on the sites. Can you actually edit your posts on here?


The content aqctually is.

Code:
		<!-- content -->
<table width="640" align="center">
<tr>
<td>
	<center><img src="/weenie1234/images/demosign1.jpg" width="313" height="232"></center>
	<p>Make your very own church sign, kinda like the ones you see <a target="_top" href="churchsigns.php">here</a>. Just enter some text and click the 'Go' button. <a target="_top" href="index.php">Or pick another design</a>.</p>
</td>
</tr>
</table>

<script language="Javascript">
function checkform(frm) {
	if (frm.line1.value.length < 1 && frm.line2.value.length < 1 && frm.line3.value.length < 1 && frm.line4.value.length < 1) {
		alert ("Please enter some text.");
		frm.line1.focus();
		return false;
	}
}
</script>

<table width="640" border="0" align="center">
<form action="/weenie1234/index2.php" method="post" onSubmit="return checkform(this)">
<tr>
<td width="40%">
line 1: <input type="text" name="line1" maxlength="22" value=""><br>
line 2: <input type="text" name="line2" maxlength="22" value=""><br>
line 3: <input type="text" name="line3" maxlength="22" value=""><br>
line 4: <input type="text" name="line4" maxlength="22" value=""><br>
<input type="submit" name="go" value="Go">
</td>
<td width="60%">
<p style="font-family: sans-serif; font-size: 11px;">(<B style="color: blue; background-color: yellow;">Note: do not link directly to the image generated on this site - it won't work.</B> You are free to download the image, copy it, put it on your own website, or distribute it however you like. If you don't have a website to store it on, there are plenty of <A TARGET="_blank" HREF="[URL unfurl="true"]http://www.google.com/search?q=free+image+hosting">free[/URL] image hosting</A> sites available.)</p>
</td>
</tr>
</form>
</table>

		<!-- /content -->
 
Hmm, i've looked around some more.
And i now know i need another script to retrieve the image that the script makes.
I was wondering if any of you knew a place where i could find a script like that, i've already looked on php,net, and phpbuilder and stuff.
Or better, could you tell me a script that would work?

Thanks in advance, monochrome.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top