title: php include generated png in pdf via fpdf
body: <p>I am trying to generate a PDF with an image that is also generated by php.
  Sounds simple enough and I am sure I'm just screwing up the header but I can't seem to find a solution here.</p>
  
  <p>first I generate a PDF:</p>
  
  <pre><code>define('FPDF_FONTPATH','fonts/');
  require('scpt/fpdf.php');
  
  class PDF extends FPDF {}
  $pdf = new FPDF('P','in',array(8.5,11));
  $pdf-&gt;SetAutoPageBreak(false,0);
  
  $pdf-&gt;SetTextColor(0,0,0);
  $pdf-&gt;SetDrawColor(0,0,0);
  $pdf-&gt;SetFont('Helvetica','',12);
  
  $pdf-&gt;Image('label.php?imgid=17',0,0,0,0,'PNG');
  
  $pdf-&gt;Output('label.pdf','D');
  </code></pre>
  
  <p>then I generate the PNG in label.php:</p>
  
  <pre><code>if(isset($_GET["imgid"])) {
   header("Content-Type: image/png");
   $im = @imagecreate(110, 20)
       or die("Cannot Initialize new GD image stream");
   $background_color = imagecolorallocate($im, 0, 0, 0);
   $text_color = imagecolorallocate($im, 233, 14, 91);
   imagestring($im, 1, 5, 5,  "A Simple Text String", $text_color);
   imagepng($im);
   imagedestroy($im);
  }
  </code></pre>
  
  <p>This will output: <code>FPDF error: Not a PNG file:....</code></p>
  
  <p>calling label.php?imgid=17 in the browser however will show me the image just fine...</p>
  
  <p>What am I missing?</p>
  
  <p>EDIT</p>
  
  <p>In document:
  Example</p>
  
  <pre><code>// Insert a logo in the top-left corner at 300 dpi
  $pdf-&gt;Image('logo.png',10,10,-300);
  // Insert a dynamic image from a URL
  $pdf-&gt;Image('http://chart.googleapis.com/chart?cht=p3&amp;chd=t:60,40&amp;chs=250x100&amp;chl=Hello|World',60,30,90,0,'PNG');
  </code></pre>
  
  <p>so it SHOULD be possible to include a dynamically generated image without saving it first?!</p>
  
  <p>EDIT #2</p>
  
  <p>I made it work with the library <a href="http://www.fpdf.org/en/script/script45.php" rel="nofollow">mem_image</a> but the problem remains that this should not throw an error IMO?! So I leave this question open to see if there is indeed something wrong with my script of this turning out to be a bug.</p>