Headless server to render a still with a given texture

I’m currently contracting for an advertising agency as a web developer. A project idea involves taking a photo of a user’s face on the web front end, mapping it onto a 3D model, and returning a 2D render. I’m investigating how we might do it.

I’m a total newbie to Blender and I have no idea if it’ll help me but since I’m a supporter of open source it seems a good place to start.

So what I’m wondering is if it’s feasible to do the following:

  • set up a scene in Blender, with a particular spot where it’s expecting a texture
  • have this scene file available on a headless Debian server
  • call some binary or script with a reference to a fresh texture file, which will call up Blender to
  • map this texture in that particular place
  • render the scene with given default camera angle etc
  • end up with the rendered output image

There’s no X windows or similar on the server – everything from step 2 needs to be headless and automated.

Is this something it’s possible to do? I’m quite happy scripting Python, if that helps. I’d have them hire someone to do the actual 3D work (maybe I’ll post in the “paid work” section of this forum if I get answers which point at this all being possible). Is there any material I can read which would be relevant? My searches so far have just turned up Blender scripting which happens in the GUI.

Thanks very much.

I have figured it out. I load the blend file with
blender -b blendfile.blend --python-console
and from here was able to change the texture and render with
import bpy
import os
bpy.data.scenes[0].render.filepath = ‘/tmp/testrender’
img = bpy.data.images.load(os.path.expanduser(’~/testtexture.png’))
bpy.data.meshes[0].materials[0].node_tree.nodes[“Image Texture”].image = img
bpy.ops.render.render(write_still=True)

I imagine it’ll be quick work from here to put that in a script file which takes the texture image and output name as arguments.