Script: assign image texture to Image Texture node I am trying to assign an image texture to an Image Texture node in 2.80. Very simple script - I'm just starting to learn how this stuff works.

This is what I have. It creates an image and and IT node, but it doesn't assign the one to other. Can anybody help? I've searched around, but can't find it in another question.

import bpy

#create blank image
bpy.ops.image.new(name="TestImg", width=1024, height=1024)

#add image texture to object, to hold baked lighting
mat = bpy.context.view_layer.objects.active.active_material
image_node = mat.node_tree.nodes.new('ShaderNodeTexImage')

#assign image to image texture node
image_node.image = "TestImg"


Thanks in advance.
The texture is not assigned because you are referring to it as a String instead of a data. Use the following code:

import bpy

# create blank image
bpy.ops.image.new(name="TestImg", width=1024, height=1024)

# get material reference
mat = bpy.context.view_layer.objects.active.active_material

# get texture reference
tex = bpy.data.images.get('TestImg')

# create node and assing the texture to it
image_node = mat.node_tree.nodes.new('ShaderNodeTexImage')
image_node.image = tex