# Is it possible to create image data from a base64 encoded PNG?

I have a base64 encoded PNG image, and I want to load this into an image. I could write a simple PNG decoder and read every pixel, but this would be very inefficient as this would be done on a per-pixel-basis through Python.

Is there a way to feed bpy.types.Image with the entire raw string of a PNG that doesn't come from disk?

This seems to work.

def image_from_data(img_name, data):
# Create image, width and height are dummy values
img = bpy.data.images.new(img_name, 8, 8)

# Set packed file data
img.pack(data=data, data_len=len(data))

# Switch to file source so it uses the packed file
img.source = 'FILE'

return img


You can also change the packed data afterwards with another .pack() call; use .reload() in that case to refresh after the change.

• That works flawless! Thanks! Oct 8, 2021 at 2:40