title: Quickest way to output image from an ajax call
body: <p>My project is an image processing script, using php, JavaScript and imagick (or imagemagick).</p>
  
  <p>Currently, a user can change properties of an image with a browser which then jscript sends an Ajax call to my php script to process the changes, resave the image and send the file path and response back to the browser so jscript can then refresh the img tag.</p>
  
  <p>I'm looking to make this process faster if possible.</p>
  
  <p>Ideally, the processing php script would be able to output the raw image data straight after its processed changes with the appropriate mime header, but this can't be done as the same file needs to send a json response.</p>
  
  <p>Any views and suggestions welcome..</p>
  
  <p><strong>EDIT: I should have mentioned what I have tried so far:</strong></p>
  
  <p>Because of the wide variety of operations available to alter the image, telling my php script what to alter via url string like <code>&lt;img src='image.php?id=132&amp;layer1=flip' /&gt;</code> the url would often exceed the recommended <a href="https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url">maximum number of characters</a>. Otherwise this would have been ideal. </p>
  
  <p>I have also tried sending the base64 raw data back and processing it and although I haven't completely ruled this one out, it's got its drawbacks - adding base 64 data to the src of an <code>&lt;img&gt;</code> is not naturally supported in all browsers. </p>