Saving a 16 bit PNG using script I'm trying to bake displacements using script but need to save the result using a 16 bit image format (such as PNG-16). How can I change the color-depth setting using script?

Example code

img = bpy.data.images.new(name="depthmap", width=imageSize,height=imageSize,alpha=False, float_buffer=True)
img.colorspace_settings.name = 'Linear'
# bake() #implemented in separate function
img.file_format = 'PNG'
# need to set to 16-bit here
img.filepath_raw = "my_new_bake.png"
img.save()
You can not directly assign the color depth on the image. However, you can make a scene and set its render.image_settings.color_depth. Then use save_render() with that scene to save the image with the color depth.

import bpy

# Create new scene to set color depth on it
scene = bpy.data.scenes.new('scene name')
settings = scene.render.image_settings
settings.color_depth = '16'
settings.file_format = 'PNG'

# Create new image and save with scene
img = bpy.data.images.new('name', width, height)
img.save_render('filepath', scene)