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
pentool12
Forum Newbie
Posts: 7 Joined: Fri Feb 21, 2014 9:00 pm
Post
by pentool12 » Fri Feb 21, 2014 9:22 pm
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:
Post
by pbs » Fri Feb 21, 2014 10:33 pm
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
Post
by pentool12 » Fri Feb 21, 2014 10:41 pm
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:
Post
by pbs » Fri Feb 21, 2014 11:30 pm
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
Post
by pentool12 » Fri Feb 21, 2014 11:35 pm
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:
Post
by pbs » Fri Feb 21, 2014 11:53 pm
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
Post
by pentool12 » Sat Feb 22, 2014 12:05 am
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:
Post
by pbs » Sat Feb 22, 2014 12:14 am
pentool12
Forum Newbie
Posts: 7 Joined: Fri Feb 21, 2014 9:00 pm
Post
by pentool12 » Sat Feb 22, 2014 12:19 am
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:
Post
by pbs » Sat Feb 22, 2014 12:23 am
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
Post
by pentool12 » Sat Feb 22, 2014 1:17 am
oh. i got it. thank you sir.