I should bring in some context. Firstly, I'm doing this on the newest release candidate 3.2.2 since that does have
save_png_to_buffer(). I'm making a drawing app, on saving the drawing gets sent to a server. The server has a REST API it's decoding base64 to png. The app is all going to be online so I can't save the drawing locally to be processed, which is where the problem is. To Marshall the png I need to have it present, I've been successful in doing it without the buffer but I need to process it in memory because the app will be online.
#This fetches the drawing
# Get the viewport image.
var img = get_viewport().get_texture().get_data()
# Crop the image so we only have canvas area.
var cropped_image = img.get_rect(Rect2(TL_node.global_position, IMAGE_SIZE))
# Save to path works to test locally but not on server
# This code does the conversion
var file = File.new() # file to store base64 data
var image = File.new() # file to open saved drawing
# convert to base64 and store in temp file
# save base64 data
data = str(file.get_as_text())
The only way I've been able to do this is by having two files locally, one png one txt file for doing the conversion. Haven't been successful any other way so far. Unless there's a way for me to do this processing online?