Skip to content

Instantly share code, notes, and snippets.

@kzerot
Last active September 25, 2020 09:42
Show Gist options
  • Save kzerot/06b5a2cb35e8ec5f5d851596cb644fed to your computer and use it in GitHub Desktop.
Save kzerot/06b5a2cb35e8ec5f5d851596cb644fed to your computer and use it in GitHub Desktop.
var loaded = {}
func get_tex_from_drive(path, flags=Texture.FLAG_FILTER, store=true):
if store and path in loaded:
return loaded[path]
var file = File.new()
if file.open(path, File.READ) == OK:
# Have file
var data : PoolByteArray = file.get_buffer(file.get_len())
var i = Image.new()
if path.get_extension() == "png":
var error = i.load_png_from_buffer(data)
if not error == OK:
print("Error loading, ", error, " ", path)
elif path.get_extension() in ["jpg", "jpeg", "JPG", "JPEG"]:
var error = i.load_jpg_from_buffer(data)
if not error == OK:
print("Error loading, ", error, " ", path)
var texture = ImageTexture.new()
texture.create_from_image(i, flags)
file.close()
if store:
loaded[path] = texture
return texture
return null
@kzerot
Copy link
Author

kzerot commented Sep 25, 2020

Simple snippet for loading images (and creating Texture from it) from outside res://

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment