how to create text on php generated image?
Moderators: onion2k, General Moderators
how to create text on php generated image?
may i know how to create text which input by user from an xhtml page into php generated image?
thanks in advance.
thanks in advance.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
imagestring() et al.
- R4000
- Forum Contributor
- Posts: 168
- Joined: Wed Mar 08, 2006 12:50 pm
- Location: Cambridge, United Kingdom
Code: Select all
<?php
if($_POST['text2write']){
$im = imagecreate(100, 30);
// white background and blue text
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);
imagestring($im, 5, 0, 0, $_POST['text2write'], $textcolor);
header("Content-type: image/png");
imagepng($im);
} else {
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="POST">
Text to write on image: <input name="text2write" value="" type="text" /><br />
<input type="submit" name="submit" value="Write It!" />
</form>
<?php
}
?>check the output of
print_r(get_loaded_extensions());
You probably do not have the gd extension loaded
Are you using windows php distro?
print_r(get_loaded_extensions());
You probably do not have the gd extension loaded
Are you using windows php distro?
i have checked in my command prompt by typing php -m
the list of php modules shows i have gd included.
but now another problem arise is, another error message is diplayed which is as below:
"Warning: Cannot modify header information - headers already sent by (output started at C:\Web Docs\Assignment\Designshirt.php:8) in C:\Web Docs\Assignment\Designshirt.php on line 231
‰PNG "
where the line 231 is " header("Content-type: image/png");"
any solutions for it?thanks in advance!
the list of php modules shows i have gd included.
but now another problem arise is, another error message is diplayed which is as below:
"Warning: Cannot modify header information - headers already sent by (output started at C:\Web Docs\Assignment\Designshirt.php:8) in C:\Web Docs\Assignment\Designshirt.php on line 231
‰PNG "
where the line 231 is " header("Content-type: image/png");"
any solutions for it?thanks in advance!
check for newlines
Check that you dont have blank lines at the top of your script, also check that only the image code is being executed when you are calling the image.
re
feyd | Please use
There must be nothing outputted to the browser before you generate the image
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
best thing would be to do is put the image code on top and use exit()Code: Select all
<?php
if($_POST['text2write']){
$im = imagecreate(100, 30);
// white background and blue text
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);
imagestring($im, 5, 0, 0, $_POST['text2write'], $textcolor);
header("Content-type: image/png");
imagepng($im);
exit();
}
?>
HTML CODE HEREfeyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Since you didn't quite get it, try doing something liketimvw wrote: Or generate it on the fly, and add an <img tag that points to your script that generates it..
Code: Select all
echo '<img src="tshirtimage.php?text='.$_POST['tshirt_text'].'">';Either pass the text to the image through the image tag, or have the script read the content directly. I would do some validating first before passing it though. To read the image as an image source, use readfile(). The user comments should be more than helpful.