php_begins Posted December 13, 2011 Share Posted December 13, 2011 i have a code that generates a random code and displays it as an image. But the problem the image can be displayed only if it is called before any other output. How do i run it so that it can be displayed after any output.. <? //Security Word for the form $codelenght = 10; while($newcode_length < $codelenght) { $x=1; $y=3; $part = rand($x,$y); if($part==1){$a=48;$b=57;} // Numbers if($part==2){$a=65;$b=90;} // UpperCase if($part==3){$a=97;$b=122;} // LowerCase $code_part=chr(rand($a,$b)); $newcode_length = $newcode_length + 1; $newcode = $newcode.$code_part; } header('Content-Type: image/png'); $im = imagecreatetruecolor(200, 40); $white = imagecolorallocate($im, 255, 255, 255); $grey = imagecolorallocate($im, 128, 128, 128); $blue = imagecolorallocate($im, 0, 0, 238); $black = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 1, 1, 200, 40, $white); $font = '/home/vhosts/master_files/advertising/fonts/arialbd.ttf'; imagettftext($im, 12, 0, 10, 18, $blue, $font, $newcode); imagepng($im); imagedestroy($im); ?> Quote Link to comment Share on other sites More sharing options...
requinix Posted December 13, 2011 Share Posted December 13, 2011 You can't. A script can output either an image or HTML - not both. Quote Link to comment Share on other sites More sharing options...
litebearer Posted December 13, 2011 Share Posted December 13, 2011 rough idea... newimage2.php <?PHP echo "see how it works"; ?> <img src="newimage.php" alt=""> <?PHP echo "did it work"; ?> newimage.php <?PHP $newcode = "test"; header('Content-Type: image/png'); $im = imagecreatetruecolor(200, 40); $white = imagecolorallocate($im, 255, 255, 255); $grey = imagecolorallocate($im, 128, 128, 128); $blue = imagecolorallocate($im, 0, 0, 238); $black = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 1, 1, 200, 40, $white); $font = 'arial.ttf'; imagettftext($im, 12, 0, 10, 18, $blue, $font, $newcode); imagepng($im); imagedestroy($im); ?> 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.