# How to save an .exr file with 32 bit with python

I'd like to create a picture in blender and save it as a 32 bit exr.

import bpy

# in case of re-runnign this code,
# get the old 'foo' image out of the way
if 'foo' in bpy.data.images:
bpy.data.images['foo'].name='bar'

#create an HDR image with name 'foo'
bpy.ops.image.new(name='foo', width=512, height=512, alpha=False, float=True)

#find the image with name 'foo'
image=bpy.data.images['foo']

# set it up for saving an exr HDR image
image.filepath_raw =  '/tmp/foo.exr'
image.file_format = 'OPEN_EXR'
# TODO here: image.save_as_32_bit=True (instead of 16)

#save image to disc
image.save()


The above code makes 16 bit exr according to imagemagick. I want to use bpy.ops.image.save_as somehow from python, in conjuction with this code, to emulate the behaviour of Image->Save as Image with the option [Float (Full)] rather than [Float (Half)]

The Save as dialogue points to a thing called ImageFormatSettings. Where can I supply this in python?

Thank you

You can change the color depth like this:

image_settings = bpy.context.scene.render.image_settings
image_settings.file_format = "OPEN_EXR"
image_setting.color_depth = '32'


Note that '32' is a string and not an integer/float. Then save the image like this:

img = bpy.data.images['myImage'] # your image here