need some help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pentool12
Forum Newbie
Posts: 7
Joined: Fri Feb 21, 2014 9:00 pm

need some help

Post by pentool12 »

i wanna put a textbox here and the input from textbox will be replace 'this is text'.

Code: Select all

<?php
$im = imagecreate(100, 30);
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 5, 0, 0, 'this is text', $textcolor);
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: need some help

Post by pbs »

this will be your form

Code: Select all

<form action="" method="post" name="frm">
	<input name="image_text" type="text" id="image_text" />
	<input name="btnSubmit" type="submit" />
</form>
so your php code will be

Code: Select all

<?php
if (isset($_POST['btnSubmit']))
{
     $im = imagecreate(100, 30);
     $bg = imagecolorallocate($im, 255, 255, 255);
     $textcolor = imagecolorallocate($im, 0, 0, 0);
     $txt = trim($_POST['image_text']);
     imagestring($im, 5, 0, 0, $txt, $textcolor);
     header('Content-type: image/png');
     imagepng($im);
     imagedestroy($im);
}
?>
hope this will help you
pentool12
Forum Newbie
Posts: 7
Joined: Fri Feb 21, 2014 9:00 pm

Re: need some help

Post by pentool12 »

it's not working sir. the img cant be load.
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: need some help

Post by pbs »

pentool12 wrote:it's not working sir. the img cant be load.
are you getting any error, its working for me
pentool12
Forum Newbie
Posts: 7
Joined: Fri Feb 21, 2014 9:00 pm

Re: need some help

Post by pentool12 »

when i submit that form, the img was crash.
i run this php file using xampp.
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: need some help

Post by pbs »

pentool12 wrote:when i submit that form, the img was crash.
i run this php file using xampp.
check if GD library is enabled, also enable error_reporting to all
pentool12
Forum Newbie
Posts: 7
Joined: Fri Feb 21, 2014 9:00 pm

Re: need some help

Post by pentool12 »

sir may you do it for me? i will pm you my t/viewer id and pword
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: need some help

Post by pbs »

pentool12
Forum Newbie
Posts: 7
Joined: Fri Feb 21, 2014 9:00 pm

Re: need some help

Post by pentool12 »

thank you very much sir. it's working

my previous code is

Code: Select all

<html>
<head>
</head>
<body>
<?php
if (isset($_POST['btnSubmit']))
{
     $im = imagecreate(100, 30);
     $bg = imagecolorallocate($im, 255, 255, 255);
     $textcolor = imagecolorallocate($im, 0, 0, 0);
     $txt = trim($_POST['image_text']);
     imagestring($im, 5, 0, 0, $txt, $textcolor);
     header('Content-type: image/png');
     imagepng($im);
     imagedestroy($im);
}
?>
<form action="" method="post" name="frm">
        <input name="image_text" type="text" id="image_text" />
        <input name="btnSubmit" type="submit" />
</form>
</body>
</html>
what error i have here?
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: need some help

Post by pbs »

take the php code at the top or use this code

Code: Select all

<?php
if (isset($_POST['btnSubmit']))
{
     $im = imagecreate(100, 30);
     $bg = imagecolorallocate($im, 255, 255, 255);
     $textcolor = imagecolorallocate($im, 0, 0, 0);
     $txt = trim($_POST['image_text']);
     imagestring($im, 5, 0, 0, $txt, $textcolor);
     header('Content-type: image/png');
     imagepng($im);
     imagedestroy($im);
}
?>
<html>
<head>
</head>
<body>
<form action="" method="post" name="frm">
        <input name="image_text" type="text" id="image_text" />
        <input name="btnSubmit" type="submit" />
</form>
</body>
</html>
pentool12
Forum Newbie
Posts: 7
Joined: Fri Feb 21, 2014 9:00 pm

Re: need some help

Post by pentool12 »

oh. i got it. thank you sir.
Post Reply