How to save texture as image file?

Godot Version 4.2.2

Hi, how do I save a texture as an image? Here’s my code:

	if Input.is_action_just_pressed("Screenshot"):
			saveScreenshot("res://screenshot.png")
		
	func saveScreenshot(path):
		var img = $Head/CameraRecoil/Camera3D.get_viewport().get_texture()
		img.flip_y()
		return img.save_png(path)

Call get_image() on the img var first.