How to reimport png files with other settings via script/code

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

I want to load many png files at runtime. Some of them should be imported as Image and others as unfiltered Texture. I am also saving Images to png at runtime as unfiltered Textures. How can I specify importsettings of a Resource via C# or GDScript?

:bust_in_silhouette: Reply From: creativeape

You can use Image.load_png_from_buffer

var f = File.new()
var err = f.open("img.png")
if err:
    print("something went wrong: " + str(err))
    return

var img_buffer = f.get_buffer(f.get_len())
f.close()

var img = Image.new()
img.load_png_from_buffer(img_buffer)

# you now have an Image, loaded as png from file.

# to create a Texture using this image:
 var tex = ImageTexture.new()
 tex.create_from_image(img)