# What context does save_as need?

I'm trying to save a texture using save_as, because I want to use the optional Copy parameter. I'm using this code:

# locals: size (int), path (string)
tex = bpy.data.images.new("MyTexture", size, size)
bpy.ops.image.save_as({"edit_image": tex}, copy=True, filepath=path)


As a result, I'm getting this:

RuntimeError: Operator bpy.ops.image.save_as.poll() failed, context is incorrect


However, I can't find any documentation about which context is needed for save_as. So my questions are:

• What is the required context for save_as?
• Where do I generally find what context is required for an operator?
• How about tex.save_render(path) – batFINGER May 8 '19 at 12:35
• It has slightly different behaviour in that it doesn't save a copy, but sets the image path, too. I do baking and I'm getting memory leaks when creating more images, so I'd like to re-use the same image to bake different channels. I know, it's a workaround around a workaround, but I'd generally like to know how to use these operators. – georch May 9 '19 at 21:58
• (And after saving the image with tex.save_render, I can't change certain parameters of the texture any more, e.g. size) – georch May 9 '19 at 21:59
• Why not? tex.scale(width, height) – batFINGER May 10 '19 at 11:05

bpy.ops.image.save_as(save_as_render=False, copy=False, filepath="", check_existing=True, filter_blender=False, filter_backup=False, filter_image=True, filter_movie=True, filter_python=False, filter_font=False, filter_sound=False, filter_text=False, filter_btx=False, filter_collada=False, filter_alembic=False, filter_folder=True, filter_blenlib=False, filemode=9, relative_path=True, show_multiview=False, use_multiview=False, display_type='DEFAULT', sort_method='FILE_SORT_ALPHA')