If it's just a matter of generating a random sprite, this could be a simple front-end script that given a random seed outputs a deterministic avatar. That seed could be based on a user-email etc and now you have a "service" without a back-end. The images are simple enough that it should be very efficient to generate and faster than a http request (provided it's written considerately)... or if it _must_ be done in the backend, you could generate a http image response on the fly based on a seed passed in the request header, again in one simple script.
[edit]
Sorry I feel bad now, but I genuinely think there is a better approach. I'm hoping you might be open to it. Here's a proof of concept that add avatars to HN based on the username:
(Just paste it in the console on this page and scroll to the top.)
const avatar = (r=1, p=16) => {
const c = document.createElement('canvas');
const x = c.getContext('2d');
c.width = 8*p;
c.height = 8*p;
for (let i=28; i--;) {
// xorshift
r ^= r << 13;
r ^= r >>> 17;
r ^= r << 5;
// pixels
const X=i&3, Y=i>>2;
if (r>>>28 > X*X+Y) {
x.fillRect(
p*3.5 + p*X,
p*0.5 + p*Y,
p, p);
x.fillRect(
p*3.5 - p*X,
p*0.5 + p*Y,
p, p);
}
}
return c;
};
// Your HN avatar ! :)
const seed = [...me.innerText]
.map(c => c.charCodeAt(0))
.reduce((a, b) => a + b);
const sprite = avatar(seed);
document.body.prepend(sprite);