title: PHP header, Content type: image not allowing text
body: <p>I have a variable (<code>$output</code>) that is set to a string.</p>
  
  <p>To mekt this string an image I'm using the <a href="http://www.php.net/manual/en/intro.image.php" rel="nofollow noreferrer">PHP: GD Library</a>.</p>
  
  <p>In particular the <a href="http://www.php.net/manual/en/function.imagestring.php" rel="nofollow noreferrer">imagestring()</a> function, which I'm using with a very slight modification:</p>
  
  <pre><code>&lt;?php
  // Create a 100*30 image
  $im = imagecreate(100, 30);
  
  // White background and blue text
  $bg = imagecolorallocate($im, 255, 255, 255);
  $textcolor = imagecolorallocate($im, 0, 0, 255);
  
  // Write the string at the top left
  imagestring($im, 5, 0, 0, $output, $textcolor); #here is my string $output
  
  // Output the image
  header('Content-type: image/png');
  
  imagepng($im);
  imagedestroy($im);
  ?&gt;
  </code></pre>
  
  <p>This is working as expected: It turns <code>$output</code> into an image.</p>
  
  <p>So, my problem is (or my best guess at least):</p>
  
  <pre><code>header('Content-type: image/png');
  </code></pre>
  
  <p>Which, doesn't allow me to output any html after that.</p>
  
  <p>So I read this question, which <a href="https://stackoverflow.com/questions/2428004/how-can-i-use-multiple-php-header-content-types-on-the-same-page-is-this-possibl">asks if you can use two headers</a>, which you can't, but <a href="https://stackoverflow.com/questions/2428004/how-can-i-use-multiple-php-header-content-types-on-the-same-page-is-this-possibl/2428022#2428022">the accepted answer</a> recommends, something like this: <code>&lt;img src="my_img.php" /&gt;</code></p>
  
  <p>This of course would be fine, except I don't know how would this solve my issues since, since even if I knew the source to this image (<strong>which I don't - so, that would be my first question, what's the path to the generated image*</strong>) I't would change the fact that the header is there and is not letting me output text.</p>
  
  <p>So, I how would you approach this issue?</p>
  
  <p>Thanks in advance!!</p>
  
  <hr>
  
  <p>*I guess that would solve my issues since I could do this on an external file, and the just call the image (but maybe not since I would have to do an include and this would include the header too) as you see I'm a bit confused. Sorry :)</p>
  
  <hr>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>So I'm seeing my question was confusing so I will add some more code to see if this clarifies my problem a little bit more:</p>
  
  <pre><code>&lt;?php
  
  $x = mt_rand(1,5);
  $y = mt_rand(1,5);
  
  function add($x, $y) { return $x + $y; }
  function subtract($x, $y) { return $x - $y; }
  function multiply($x, $y) { return $x * $y; }
  
  $operators = array(
      'add',
      'subtract', 
      'multiply'
      );
  
  $rdno = $operators[array_rand($operators)];
  
  $result = call_user_func_array($rdno, array($x, $y));
  session_start();
  $_SESSION['res'] = $result;
  
  if ($rdno == "add") {
      $whato = "+";
  }elseif ($rdno == "subtract") {
      $whato = "-";
  } else {
      $whato = "*";
  }
  $output = $x . $whato . $y . " = ";
  ?&gt;
  &lt;form name="input" action="check.php" method="post"&gt;
  &lt;input type="text" name="result" /&gt;
  &lt;input type="submit" value="Check" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>I want <code>$output</code> to be a image</strong> so this got me trying to use the PHP:GD script above, but I can't make put in the same file because of the header.</p>