(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.)
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., [3, 2, 1]
.
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,
montage 3.png 2.png 1.png 321.png
creates a new single image, 321.png, composed of 3.png, 2.png, and 1.png, all in a row.
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.)