Bpy.ops.image.open() supported formats

I am using ImportHelper to select images to load with bpy.ops.image.open().

Is there a way with python to find the list of supported file format for bpy.ops.image.open() so
I could set up my filter_glob correctly ?

filter_glob: StringProperty(
        default="*.psd;*.tif", <<= filling this part with python instead of manually 
        maxlen=255,  # Max internal buffer length, longer would be clamped.

edit 1:
Currently made a list from https://docs.blender.org/manual/en/latest/files/media/image_formats.html
but it’s not accurate. For exemple there’s no .psd support in that list, but blender can open that format without troubles.

You mean something like this?

import bpy

formats = ['*.bmp', '*.jpg', '*.tif', '*.png']
files = bpy.props.StringProperty(
    default = ', '.join(formats)

1 Like

No, In your example, you manually fill formats. I was looking for something like
Image.query_supported_format to fill it automatically but it doesn’t exist from what I’ve seen.

It is more about polish than anything though, not having it won’t break anything.

Thanks for answering !

Fun fact, you could try doing this crazy idea, with an HTTP request get the page content, and retrieve the substring with the file formats, then save them in a custom .py file (autogenerated python file).


1 Like

Good idea and I think it’s the closest I’ll get to do it the python way.

You can get all supported image extensions using:

>>> bpy.path.extensions_image
frozenset({'.psb', '.tx', '.psd', '.rgba', '.tga', '.jp2', '.png', '.j2c', '.bmp', '.cin', '.pdd', '.tiff', '.sgi', '.rgb', '.exr', '.dpx', '.dds', '.jpeg', '.jpg', '.hdr', '.tif'})

Hard to find without using the python console, the attribute is undocumented for whatever reason:

import bpy
import os.path

image_path = bpy.path.abspath("//Screenshot 2021-11-20 at 15.45.41.png")
filename, file_extension = os.path.splitext(image_path)
if file_extension in bpy.path.extensions_image:
    print("Extension supported")

Alternatively you could also convert the set into a tuple and use str.endswith():

>>> "//directory/final.exr".endswith(tuple(bpy.path.extensions_image))


1 Like