A model I downloaded has textures packed that are in TGA format. I want to convert the images into PNG format because it takes up less storage space. Is there a way I can easily convert all the files without having to unpack them, and replace the textures one by one?
-
$\begingroup$ The first thing I thought of was unpacking all, converting externally with FFMPEG or Python PIL, and then blender scripting them back in with the different file name extension. Shouldn’t be too hard with bpy.data $\endgroup$– TheLabCatMay 1, 2021 at 3:27
-
$\begingroup$ @ZargulTheWizard ...but only if you know how to use python and you can develop a bit with python - which not everybody is capable of... ;) $\endgroup$– ChrisMay 1, 2021 at 4:10
-
$\begingroup$ Or you could unpack the Blend Files, open in photoshop or Gimp and export as PNG. But if you hace like 100 or more, is going to take a while $\endgroup$– EmirMay 1, 2021 at 12:59
-
$\begingroup$ @Chris oh, alright. Hang on… $\endgroup$– TheLabCatMay 1, 2021 at 13:02
1 Answer
This is easily done with Python scripting, but I include in that statement a non-blender Python installation on your system. To do what you want from scratch:
- Backup the blend file!
- Go to python.org and download the latest Python (not the embeddable version).
- Install Python on your system, and check the “add Python to PATH” when it comes up.
- At the Command Prompt, type:
python -m pip install pillow
and it will download and install the Python imaging library (an easy way to convert the files). - In blender, unpack all images to one folder using the File menu (“use local directory” probably will work, but make sure nothing else is in there except the blend file).
- Open IDLE (the Python IDE you just installed. You will see a Python shell.
- Run the following code in that shell:
from PIL import Image
import glob
files=glob.glob(“C:\\Users\\Anthony\\the_blend_directory_here\\*”)
for f in files:
Image.open(f).save(f.replace(“.tga”, “.png”))
- The script should convert all unpacked images to png, one at a time. Close the Python shell upon verifying success.
- In blender, go to the Scripting screen, and run the following code:
for img in bpy.data.images:
img.filepath=img.filepath.replace(“.tga”, “.png”)
img.reload()
- Re-pack all files.
- Delete the external images.
-
$\begingroup$ Sorry, I couldn’t get the code to separate properly :( I hope you can still read it $\endgroup$ May 1, 2021 at 23:46