(4x) Convert image from user:// to res://, then make an imagetexture out of it with code

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

Im trying to make it so it will pull an image of your choice from the user:// folder, it then makes it a res:// image and sets it as an imagetexture to show up on a panel node to display it to you in-game. Ive tried as much as I could bit it always ends in an error. Last error says invalid set index 'texture' (on base: 'ImageTexture') with type: 'image'.
The local_data dictionary is the path.

match local_data["files"][id][id]["file_type"]:
	"png":
		var image = Image.new()
		var preview_tex = ImageTexture.new()
		image.load(game.local_data["files"][id][id]["image"])
		var path_split = game.local_data["files"][id][id]["image"].split("//")
		var res_path = "res://" + str(path_split[1])
		
		preview_tex.create_from_image(image)
		preview_tex.texture = image
		image_preview.add_theme_stylebox_override("panel",preview_tex)
		no_prev_label.hide()
:bust_in_silhouette: Reply From: zhyrin

Keep in mind, once a project is exported, you can’t write to res://.
Why do you need an image in user:// to be in res://? Also, you don’t even use your res_path variable.

ImageTexture doesn’t have a texture member (third to last line), you have to use the set_image() method.

I was tinkering with it which is why there are unused variables in it. res_path did have a use but was removed because it kept erroring. My goal is to make it so you can select an image from user:// and to apply it as the wallpaper or profile picture.
I know how to do the imagetexture part, I’ve done it with the wallpaper functionality, but the image importing is quite a challenge.

How do you import an image from user:// to use it in the game then? (with code)

MythicalDesigner | 2023-03-24 16:22