I need to invert an image running blender from the command line using the -background
flag. To archive it I need to make the image active and later apply the invert
operator.
I managed to select and invert the image with Blender running the UI, with the following code:
# Select the active image
m = bpy.context.area.type
bpy.context.area.type = "IMAGE_EDITOR"
bpy.context.area.spaces.active.image = myImageToInvert
# Operate over the selected image
bpy.ops.image.invert(invert_r=True, invert_g=True, invert_b=True)
But this code does not run when Blender is called from the command line with the -background
flag, because the UI is not loaded so bpy.context.area
is null
.
How can I select the image (myImageToInvert
) in the background so bpy.ops.image.invert()
can operate over my image?
Thank you
bpy.ops.image.pack()
... So I can automate all the pipeline, not just the invert process. $\endgroup$