Last active
September 25, 2020 09:42
-
-
Save kzerot/06b5a2cb35e8ec5f5d851596cb644fed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple snippet for loading images (and creating Texture from it) from outside res://