how to create text on php generated image?

GD and GD2 are useful libraries for creating graphics on-the-fly. Discuss your PHP GD and GD2 scripts here.

Moderators: onion2k, General Moderators

lanny
Forum Newbie
Posts: 24
Joined: Thu Apr 06, 2006 10:09 am

Post by lanny »

so the php script will be placed at another php file...and the xhtml use the code above to call the php script?
i'm still quite blur..so sorry...
thanks in advance..
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

correct.
lanny
Forum Newbie
Posts: 24
Joined: Thu Apr 06, 2006 10:09 am

Post by lanny »

i went through a tutorial and found out the code
" <DIV style="position: absolute; top:511px; left:428px; width:94px; height:24px">text</DIV>"

now, the text can be placed on the shirt...but how to code, if i wanna let user add the text by entering the text on input box, then click on submit button..the text will displayed on shirt?
thanks in advance
lanny
Forum Newbie
Posts: 24
Joined: Thu Apr 06, 2006 10:09 am

Post by lanny »

the text can be displayed on the image already
code is "

Code: Select all

<DIV style="position: absolute; top:511px; left:428px; width:94px; height:24px">
<?php
echo " " . $_POST["text2write"] . "<br/>";
?></DIV>

however, the text will be only displayed on this particular page. So, if user click button 'click to preview' which  will lead user to next page and preview the image with the text again, do i nid to save the text into the database?
or passing the variable is sufficient enough?

thanks in advance!
[/quote]
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

passing the code should be sufficient enough.. I would probably pass the input through htmlentities() just to be safe aswell
lanny
Forum Newbie
Posts: 24
Joined: Thu Apr 06, 2006 10:09 am

Post by lanny »

OK..THANKS everyone!
MilkmanDan
Forum Newbie
Posts: 1
Joined: Wed Jun 14, 2006 8:21 pm

Followup

Post by MilkmanDan »

I've been lurking and lurning, and thought I'd ask this in here instead of a new thread. In R4000's example (below) I'm pretty sure I have a handle on whats happening throughout, and I have no problem getting it to run.....but when displaying the created image......if I try to "Right-click/Save" the generated image it will only save the php-form. What else has to be there for the image to be savable from the browser window?

I also have tried a few different ways of escaping the php to insert some text along with the generated pic. No Dice, and I'm thinking there's something here I just am not "getting". I thought that ?>Text Here<?php would work, but it just starts displaying what looks like the code for the image.

Any clues here would be greatly appreciated!
R4000 wrote:

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
}
?>
Should do exactly what you want
Post Reply