Creating Image Files with Data

Godot Version

4.5

Question

I’ve been meaning to create procedurally generated textures (3x3), but I’m unsure of how to properly save data as an image. I have been given this solution:

My 2 questions are as follows:

  1. I’d like to use RGBA values to set the color. The fourth argument, “format: Image.Format” has a format called RBGB8. Is RGB8 the best format to use for what I’d like to do?
  2. I was told to "fill it with ‘Image.set.pixel()’ but how does this target the image that was just created? How do I format the color argument?

The docs linked in that post have a good example, the created image is given as a reference from Image.create

var img_width = 10
var img_height = 5
var img = Image.create(img_width, img_height, false, Image.FORMAT_RGBA8)

img.set_pixel(1, 2, Color.RED) # Sets the color at (1, 2) to red.

set_pixel

Use RGBA8 if you want to use alpha, when you create textures from the image it doesn’t matter as much, it will always include alpha.