Crazydog115 Posted August 21, 2006 Share Posted August 21, 2006 How would I include a form processor that creates an image in another webpage?I can't just put the php in, since I need to reset the header to png, [code]header("Content-Type: image/png");[/code]So how would I include it so I can change the headers? Quote Link to comment https://forums.phpfreaks.com/topic/18149-php-image-creation-in-another-page/ Share on other sites More sharing options...
HuggieBear Posted August 21, 2006 Share Posted August 21, 2006 Is it something like this that you want?[url=http://www.dizzie.co.uk/php/test.php]http://www.dizzie.co.uk/php/test.php[/url]This page (test.php) check's to see if a form value (in this instance 'name') is set. If it's set then it calls image.php and displays the result on test.php, if not it displays the form on test.php.Here's the code for the two pages, with correct content header types.test.php[code]<?phpheader("Content-Type: text/html");if (!isset($_POST['name'])){?><h4>Enter your firstname</h4><form action="test.php" method="post"><input type="text" name="name"><input type="submit" name="submit" value="Create Image"><?php}else {?><img src="image.php?name=<?php echo $_POST['name'] ?>"><br><br><a href="test.php">Try again</a><?php}?>[/code]Here's the code for image.php[code]<?php header("Content-type: image/png"); $string = $_GET['name']; $im = imagecreatefrompng("../logos/pubutton.png"); $height = imagesy($im); $halfheight = $height / 2; $width = imagesx($im); $halfwidth = $width / 2; $fontsize = 48; $angle = 0; $font = "../logos/smartie.ttf"; $bg = imagecolorallocate($im, 255,255,255); $white = imagecolorallocate($im,255,255,255); $black = imagecolorallocate($im,0,0,0); $array = imagettfbbox($fontsize,$angle,$font,$string); $textwidth = abs($array[2] - $array[0]); $halftextwidth = $textwidth / 2; $textheight = abs($array[5] - $array[3]); $halftextheight = $textheight / 2; $xpos = $halfwidth - $halftextwidth; $ypos = $halfheight + $halftextheight; imagettftext($im, $fontsize, $angle, $xpos, $ypos, $black, $font, $string); imagepng($im); imagedestroy($im); ?>[/code]Obviously your image.php file would probably look a lot different from mine.RegardsRich Quote Link to comment https://forums.phpfreaks.com/topic/18149-php-image-creation-in-another-page/#findComment-77950 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.