2

I do not want my alpha premultiplied when saving images. In blender you can use the compositor Alpha Convert Node to convert from Premultiplied to Straight. I can't seem to find this node in the Python API.

Ray Mairlot
  • 29,192
  • 11
  • 103
  • 125
Math_Max
  • 183
  • 10

1 Answers1

3

CompositorNodePremulKey

You can find a complete list of available compositor node types here: https://docs.blender.org/api/current/bpy.types.CompositorNode.html.

alpha_convert = tree.nodes.new(type='CompositorNodePremulKey')
alpha_convert.mapping = 'PREMUL_TO_STRAIGHT'

However, sometimes it's pretty hard to figure out since the names doesn't really match. I'd suggest create the node in the compositor by hand and print its type to the console to get an idea:

import bpy

class NodeOperator(bpy.types.Operator): """Tooltip""" bl_idname = "node.simple_operator" bl_label = "Simple Node Operator"

@classmethod
def poll(cls, context):
    space = context.space_data
    return space.type == 'NODE_EDITOR'

def execute(self, context):
    space = context.space_data
    node_tree = space.node_tree
    node_active = context.active_node

    print (node_active.type)
    return {'FINISHED'}

def register(): bpy.utils.register_class(NodeOperator)

def unregister(): bpy.utils.unregister_class(NodeOperator)

if name == "main": register()

Or use Node.bl_rna attribute which returns the actual struct (to copy the name from):

>>> node_active.bl_rna
<bpy_struct, Struct("CompositorNodePremulKey")>

Related: Controling compositor by python

brockmann
  • 12,613
  • 4
  • 50
  • 93