title: PHP GD: How to get imagedata as binary string?
body: <p>I'm using a solution for assembling image files to a zip and streaming it to browser/Flex application. (ZipStream by Paul Duncan, <a href="http://pablotron.org/software/zipstream-php/" rel="noreferrer">http://pablotron.org/software/zipstream-php/</a>).</p>
  
  <p>Just loading the image files and compressing them works fine. Here's the core for compressing a file:</p>
  
  <pre><code>// Reading the file and converting to string data
  $stringdata = file_get_contents($imagefile);
  
  // Compressing the string data
  $zdata = gzdeflate($stringdata );
  </code></pre>
  
  <p>My problem is that I want to process the image using GD before compressing it. Therefore I need a solution for converting the image data (imagecreatefrompng) to string data format:</p>
  
  <pre><code>// Reading the file as GD image data
  $imagedata = imagecreatefrompng($imagefile);
  // Do some GD processing: Adding watermarks etc. No problem here...
  
  // HOW TO DO THIS??? 
  // convert the $imagedata to $stringdata - PROBLEM!
  
  // Compressing the string data
  $zdata = gzdeflate($stringdata );</code></pre>
  
  <p>Any clues?</p>