Replace image in a shader with another one

I have a file with a bunch of meshes (over 140) and each one has a shader with 2 image textures (base colour and a normal). All these image files are 4K .bmp files and each is around 50MB in size. This causes the file to be quite slow (especially when switching to rendered viewport shading or rendering, since it needs to load all of the large images). I would like to replace all the .bmp files with .jpg or .png files of the same name. Is it possible to do this with a python script?

I tried to google a bit but I couldn’t find anything that would help me figure this out :slight_smile:

This should do it, assuming you’re fine with replacing all the images in your file :

import bpy

for img in bpy.data.images:
    img.filepath = img.filepath.lower().replace(".bmp", ".jpg")

Link to the docs

1 Like

Thank you! That worked well! So simple!