dingleberry
Programmer
Hey Everyone,
<brownnose>
I have not posted on this forum for some time however I really might be in trouble here so I thought if there was any group of people out there who could give me some help, I'd find it here.
</brownnose>
Here goes:
I'm using the gd functionality in php to dynamically create images. Essentially these images are simply buttons. To do this, I have the user fill in a text field in a form and submit it to php script where this happens.
<?
$name = $_POST['name'];
$text[] = $_POST['text'];
Header("Content-type: image/jpeg"
;
if(!isset($s)) $s=11;
$size = imagettfbbox($s,0,"/home/fonts/verdana.ttf", $text);
$dx = abs($size[2]-$size[0]);
$dy = abs($size[5]-$size[3]);
$xpad=9;
$ypad=9;
$im = imagecreate($dx+$xpad,$dy+$ypad);
$blue = ImageColorAllocate($im, 0x2c,0x6D,0xAF);
$black = ImageColorAllocate($im, 0,0,0);
$white = ImageColorAllocate($im, 255,255,255);
ImageRectangle($im,0,0,$dx+$xpad-1,$dy+$ypad-1,$black);
ImageRectangle($im,0,0,$dx+$xpad,$dy+$ypad,$white);
ImageTTFText($im, $s, 0, (int)($xpad/2)+1, $dy+(int)($ypad/2), $black, "/home/fonts/verdana.ttf", $text);
ImageTTFText($im, $s, 0, (int)($xpad/2), $dy+(int)($ypad/2)-1, $white, "/home/fonts/verdana.ttf", $text);
// Imagejpeg($im,"$name.jpg"
;
Imagejpeg($im);
ImageDestroy($im);
?>
Everything is working out swell when the input is entered in as one line in a text field however when the user enters text in a textarea with multiple lines of input and perhaps some \r\n's in there, only the last line of input gets created into a image. The rest is disregarded. I'm really trying to create an image using the text inputted into a textarea field and have that image essentially emulate the formatting in the textarea field. Does this make sense? So if a user inputs the word "home" into a textfield box it generates a button that says home. But if the user inputs
"Hi, my name is
Dan and this
is a link to my
home page"
in a textarea box, then an image that displays that same text is generated with the line breaks and word wraps in the same exact location. Any help on this subject would be massively apprecited as this has eluded me for about 3 days now.
Thank You,
dan
<brownnose>
I have not posted on this forum for some time however I really might be in trouble here so I thought if there was any group of people out there who could give me some help, I'd find it here.
</brownnose>
Here goes:
I'm using the gd functionality in php to dynamically create images. Essentially these images are simply buttons. To do this, I have the user fill in a text field in a form and submit it to php script where this happens.
<?
$name = $_POST['name'];
$text[] = $_POST['text'];
Header("Content-type: image/jpeg"
if(!isset($s)) $s=11;
$size = imagettfbbox($s,0,"/home/fonts/verdana.ttf", $text);
$dx = abs($size[2]-$size[0]);
$dy = abs($size[5]-$size[3]);
$xpad=9;
$ypad=9;
$im = imagecreate($dx+$xpad,$dy+$ypad);
$blue = ImageColorAllocate($im, 0x2c,0x6D,0xAF);
$black = ImageColorAllocate($im, 0,0,0);
$white = ImageColorAllocate($im, 255,255,255);
ImageRectangle($im,0,0,$dx+$xpad-1,$dy+$ypad-1,$black);
ImageRectangle($im,0,0,$dx+$xpad,$dy+$ypad,$white);
ImageTTFText($im, $s, 0, (int)($xpad/2)+1, $dy+(int)($ypad/2), $black, "/home/fonts/verdana.ttf", $text);
ImageTTFText($im, $s, 0, (int)($xpad/2), $dy+(int)($ypad/2)-1, $white, "/home/fonts/verdana.ttf", $text);
// Imagejpeg($im,"$name.jpg"
Imagejpeg($im);
ImageDestroy($im);
?>
Everything is working out swell when the input is entered in as one line in a text field however when the user enters text in a textarea with multiple lines of input and perhaps some \r\n's in there, only the last line of input gets created into a image. The rest is disregarded. I'm really trying to create an image using the text inputted into a textarea field and have that image essentially emulate the formatting in the textarea field. Does this make sense? So if a user inputs the word "home" into a textfield box it generates a button that says home. But if the user inputs
"Hi, my name is
Dan and this
is a link to my
home page"
in a textarea box, then an image that displays that same text is generated with the line breaks and word wraps in the same exact location. Any help on this subject would be massively apprecited as this has eluded me for about 3 days now.
Thank You,
dan