Navigate --

About
Email/Contact
Open Chat Board

Old Rants --

 

Blogs --


Websites --

Michael Savage
Michael Medved
Heavysheep.com
Yaaahhhoo!
Macromedia
Stick Page
Gizoogle
Heir to the Throne - Online Game


Bloggers for Mike McGavick for Senate 2006!

Members --

 
 

We Eat Liberals for breakfast, lunch AND dinner. Don't like it? Email us


7.27.2004

Church Sign Generator source code

 - Unknown

Here is the source code for the Church Sign Generator that Brian used
in his post.




/* check the referer header */
$ref = strtolower(getenv("HTTP_REFERER"));
$pos = (substr($ref, 0, 33) == "http://www.aboyandhiscomputer.com" ? 1 : 0);
$pos += (substr($ref, 0, 29) == "http://aboyandhiscomputer.com" ? 1 : 0);
$pos += (substr($ref, 0, 20) == "http://216.22.32.139" ? 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/chars.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);

?>


Link ---------------------------------------------------------------------------------

Free Domain Forwarding

add text << # St. Blog's Parish ? >>

Humor & fun cool stuff