How can I layer and export an image?

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

So, making a portrait maker. User can choose between different hair, eyes, clothing, etc options. It shows up just fine in the project as a bunch of TextureRects. However, I have no clue how to save the image. I’ve scaled down the textures to fit on screen so I can’t just capture the viewport. Previously, I just created a new Image and then replaced all pixels that weren’t transparent with the pixel from the TextureRects in succession. But that was for pixel art. If I did that with the resolution of the portraits I’m going to use for this one, I would have to iterate over 8 million times per image.

What should I do to export the images from this portrait maker? Should I use something besides Godot? If so, what?

I decided to just run the code anyway and it took 1.7 seconds to save an image. I guess that’s acceptable. Maybe I’ll put up a loading animation. Still wonder if there’s a better way to do this.

exuin | 2020-12-23 18:56

:bust_in_silhouette: Reply From: Lopy

You can take a full screenshot like that :
var img:Image = get_viewport().get_texture().get_data()
img.flip_y()
var texture := ImageTexture.new()
texture.create_from_image(img)

I’ve scaled down the textures to fit on screen so I can’t just capture the viewport.

Plus, I want a transparent background and taking a screenshot wouldn’t give me one.

exuin | 2020-12-23 23:15