There are several problems with your method.
Ways to load an image
var old_texture = load(res://test_image.png)
var old_image = old_texture.get_data()
A "texture" is how we call an image on the graphics card.
This code loads the imported image from disk, uploads it to your graphics card, and gives you a texture object. Then it downloads it back into memory (which is much slower than upload), while the texture remains unused.
Unless you really want the output of an operation occurring on the graphics card (like a screenshot or shader output), you don't need to do it that way.
There are two alternatives:
Image to load a file.
var old_image = Image.new()
Drawback: if used in an exported game, it won't work on files under
res://, but it should be preferred on images provided by the user.
2) Import your file as an Image
Double-click on your image in the Godot file explorer, and look at the Import dock. You can make it so it is imported as an
Image, which means your current code will then return an
Image straight away, without the need to use
However, if you ALSO want to use that image as a texture so you can draw it on screen, importing as
ImageTexture might be better, so that Godot will be able to keep the image both on graphics card and in memory. Unfortunately this option is not available, so could be created manually I guess.
If you don't mind about performance,
get_data() is fine, just be aware of the implications I described ;)
Ways to save it
Problem in your code:
var new_texture = ImageTexture.new()
This code creates a new texture and uploads the image to the graphics card, and then attempts to save it under Godot TEXT format. Again, the graphics card had no reason to be used, and the format you choose is really bad for image data.
If you want the output to be a PNG file, don't use
ResourceSaver. There isn't one specifically for images, so you have to use a more specific API:
This will produce a regular PNG which is more suitable and lighter.