2
$\begingroup$

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.

$\endgroup$
3
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.