I have a project that where I want the user to be able to save a screenshot in-game to their filesystem.
Here's how I generate the screenshot image:
get_viewport().set_clear_mode(Viewport.CLEAR_MODE_ONLY_NEXT_FRAME)
yield(VisualServer, "frame_post_draw")
var img = self.get_viewport().get_texture().get_data()
img.flip_y()
img.save_png("res://screenshot.png")
When the project is exported as a desktop app (tested on windows), this works just fine and saves the generated image to the project's directory.
However, in a web export, this doesn't work. Nothing is prompted for the user to save the image.
I tried a work around where it'd open the image in a new tab so the user could save it from there, using the below code:
var url = "data:image/png;base64," + Marshalls.raw_to_base64(img.data.data)
OS.shell_open(url)
But this doesn't work. Godot's OS.shell_open()
doesn't seem to recognize data:image/png;base64,
as a link to open using the web browser.
Is there anyway for me to save an image from a Godot project to the user's filesystem (either directly or by popping up a file-save prompt or by opening the image in a new tab) in a web exported build?