image script help
I need to add a line break to my text area form field so the text entered will return on two seperate line when a return is used inside of the form.
The form can be located http://catchattention.com/picgen/test.html
I tried this bit of php
$text = ereg_replace("(rn|n|r)", "", $text);
to accomplish this but no dice.
If anyone can help I would be grateful
here is the code
<?
// Send png image header
header("Content-Type: image/png");
// Declare some vars
$text = $_GET['text'];
$tmp_font = $_GET['font'];
$fontsize = $_GET['fontsize'];
$tmp_fontcolor = $_GET['fontcolor'];
$tmp_bgcolor = $_GET['bgcolor'];
$text = ereg_replace("(rn|n|r)", "", $text);
// Set font
switch($tmp_font)
{
case "5cent":
$font = "fonts/5cent.ttf";
break;
case "airone":
$font = "fonts/airone.ttf";
break;
case "arial":
$font = "fonts/arial.ttf";
break;
case "comic":
$font = "fonts/comic.ttf";
break;
case "cour":
$font = "fonts/cour.ttf";
break;
case "georgia":
$font = "fonts/georgia.ttf";
break;
case "impact":
$font = "fonts/impact.ttf";
break;
case "lastninja":
$font = "fonts/lastninja.ttf";
break;
case "verdana":
$font = "fonts/verdana.ttf";
break;
case "xbox":
$font = "fonts/xbox.ttf";
break;
}
// Calc the text size
$box = ImageTTFbbox($fontsize, 0, $font, $text);
// Calc some props for the image
$width = $box[2] - $box[0];
$height = $box[1] - $box[7];
// 10 px empty space on each side
$imagewidth = $width + 30;
$imageheight = $height + 20;
// Create the image
$pic = ImageCreate($imagewidth, $imageheight);
// Set the colors
// Backgroundcolor
switch($tmp_bgcolor)
{
case "red":
$bgcolor = ImageColorAllocate($pic, 255, 0, 0);
break;
case "blue":
$bgcolor = ImageColorAllocate($pic, 0, 0, 255);
break;
case "green":
$bgcolor = ImageColorAllocate($pic, 0, 255, 0);
break;
case "yellow":
$bgcolor = ImageColorAllocate($pic, 255, 255, 0);
break;
case "orange":
$bgcolor = ImageColorAllocate($pic, 236, 116, 10);
break;
case "pink":
$bgcolor = ImageColorAllocate($pic, 255, 128, 255);
break;
case "lblue":
$bgcolor = ImageColorAllocate($pic, 0, 255, 255);
break;
case "grey":
$bgcolor = ImageColorAllocate($pic, 192, 192, 192);
break;
case "black":
$bgcolor = ImageColorAllocate($pic, 0, 0, 0);
break;
case "white":
$bgcolor = ImageColorAllocate($pic, 255, 255, 255);
break;
}
// Fontcolor
switch($tmp_fontcolor)
{
case "red":
$fontcolor = ImageColorAllocate($pic, 255, 0, 0);
break;
case "blue":
$fontcolor = ImageColorAllocate($pic, 0, 0, 255);
break;
case "green":
$fontcolor = ImageColorAllocate($pic, 0, 255, 0);
break;
case "yellow":
$fontcolor = ImageColorAllocate($pic, 255, 255, 0);
break;
case "orange":
$fontcolor = ImageColorAllocate($pic, 236, 116, 10);
break;
case "pink":
$fontcolor = ImageColorAllocate($pic, 255, 128, 255);
break;
case "lblue":
$fontcolor = ImageColorAllocate($pic, 0, 255, 255);
break;
case "grey":
$fontcolor = ImageColorAllocate($pic, 192, 192, 192);
break;
case "black":
$fontcolor = ImageColorAllocate($pic, 0, 0, 0);
break;
case "white":
$fontcolor = ImageColorAllocate($pic, 255, 255, 255);
break;
}
// Set the fontstart positions
$xstart = 10;
$ystart = $imageheight - 10;
// Write the text
ImageTTFText($pic, $fontsize, 0, $xstart, $ystart, $fontcolor, $font, $text);
// Finish image
ImagePng($pic);
// Clean up memory
ImageDestroy($pic);
?>
Suzanne posted this at 21:19 — 18th May 2004.
She has: 5,507 posts
Joined: Feb 2000
The hidden characters are \r and \n --
<?php
$text = ereg_replace(\"(\r\n|\n|\r)\", \"<br />\", $text);
?>
I haven't even used or within ereg, so ymmv.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.