1
$\begingroup$

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?

$\endgroup$
4
  • $\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$
    – TheLabCat
    May 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$
    – Chris
    May 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$
    – Emir
    May 1, 2021 at 12:59
  • $\begingroup$ @Chris oh, alright. Hang on… $\endgroup$
    – TheLabCat
    May 1, 2021 at 13:02

1 Answer 1

1
$\begingroup$

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:

  1. Backup the blend file!
  2. Go to python.org and download the latest Python (not the embeddable version).
  3. Install Python on your system, and check the “add Python to PATH” when it comes up.
  4. 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).
  5. 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).
  6. Open IDLE (the Python IDE you just installed. You will see a Python shell.
  7. 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”))
  1. The script should convert all unpacked images to png, one at a time. Close the Python shell upon verifying success.
  2. 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()
  1. Re-pack all files.
  2. Delete the external images.
$\endgroup$
1
  • $\begingroup$ Sorry, I couldn’t get the code to separate properly :( I hope you can still read it $\endgroup$
    – TheLabCat
    May 1, 2021 at 23:46

You must log in to answer this question.