grounded_vertigo Posted April 7, 2006 Share Posted April 7, 2006 Hi,Sorry if this is an obvious question, I am wanting to place text that a user inputs into an imagestring, I know how to place standard text in an imagestring, but can't work out how to call information from a form into part of the imagestring....I hope that makes some sense and someone can help me! Quote Link to comment Share on other sites More sharing options...
Barand Posted April 8, 2006 Share Posted April 8, 2006 Here's a sampleSave this code as "textimage.php"[code]<?php// get user text from url querystring$usertext = $_GET['txt'];if (strpos($usertext,"\r")!==false) $lines = explode ("\r\n", $usertext); // winelse $lines = explode ("\n", $usertext); // nix$maxlen = 0;$lineht = 20;// get max line length in pixelsforeach($lines as $k=>$txt) { $len = imagefontwidth(2)*strlen($txt); if ($len > $maxlen) $maxlen = $len;}// create image with 20px margins$ix = $maxlen+40;$iy = count($lines)* $lineht + 40;$im = imagecreate($ix, $iy);$black = imagecolorallocate($im, 0,0,0);$textcol = imagecolorallocate($im, 0xFF, 0xFF, 0x00);// write text lines in the imageforeach ($lines as $k=>$txt) { $y = 20 + $k * $lineht; $x = 20; imagestring($im, 2, $x, $y, $txt, $textcol);}header ("content-type: image/png");imagepng($im);imagedestroy($im);?>[/code]Save as "sample.php" and run in browser:[code]<?phpif (isset($_GET['txt'])) { $txt = urlencode($_GET['txt']); echo "<img src='textimage.php?txt=$txt'>";}?><form><TEXTAREA name='txt' rows='4' cols='30'></TEXTAREA><INPUT TYPE='SUBMIT' name='sub' value='Show text image'></form>[/code] Quote Link to comment Share on other sites More sharing options...
grounded_vertigo Posted April 10, 2006 Author Share Posted April 10, 2006 [!--quoteo(post=362759:date=Apr 8 2006, 04:44 AM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Apr 8 2006, 04:44 AM) [snapback]362759[/snapback][/div][div class=\'quotemain\'][!--quotec--]Here's a sample...[/quote]Thanks Barand, you're a star just what I was looking for!Michelle Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.