title: Php webservice that takes JSON via POST and spits back an image
body: <p><em>(Preamble: This seems like such a typical thing to want to do that I was surprised I didn't immediately find examples and tutorials about it.
  So I thought it would be valuable to have as a StackOverflow question.
  Pointers to related examples and tutorials will certainly be welcome answers.)</em></p>
  
  <p>To make this concrete, the goal is a webservice that accepts data in JSON format via a POST request.
  The data is simply an array of single-digit integers, e.g., <code>[3, 2, 1]</code>.</p>
  
  <p>On the server are images named 0.png, 1.png, 2.png, etc.
  The webservice takes the images corresponding to those specified in the JSON array and composes them into a montage, using the standard ImageMagick command line tool.
  For example,</p>
  
  <pre><code>montage 3.png 2.png 1.png 321.png
  </code></pre>
  
  <p>creates a new single image, 321.png, composed of 3.png, 2.png, and 1.png, all in a row.</p>
  
  <p>The accepted answer will be in the form of complete PHP code that implements the above.
  (I'll write it if no one beats me to it.)</p>