Dynamically create a texture from multiple images

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By shavlor

I am looking to create a new texture using two or more images.
This must be done completely within GD code using GoDot 3.1 and should not be displayed on the scene.

I have been playing around with viewports which looked promising, but my understanding is that they must be connected to a scene that is actually being displayed otherwise they do not render, and I want to do this completely off the screen then use the newly created texture

I currently am using blit_rect_mask method in the Image class however this does not allow alpha values in between 0 and 1 for the image mask so I cannot utilize alpha values from the two images.

What I was hoping for would be something like this:

func merge_images():
var s1 = Sprite.new()
s1.texture = load("res://image1.png")
var s2 = Sprite.new()
s2.texture = load("res://image2.png")
var c = Canvas.new()
c.add_child(s1)
c.add_child(s2)
s1.position = Vector2(5,5)
s2.position = Vector2(10,10)
#get texture of the two images merged together
return texture

Any help is appreciated, but please note that I want to do this completely in GD code so that I can call it dynamically.