acoolrocket

Blender - Converting textures to .webp then reassigning .png, .jpg, etc. textures as .webp

Nov 11th, 2025
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. import bpy
  2. import os
  3.  
  4. count = 0
  5.  
  6. for image in bpy.data.images:
  7. if image.filepath:
  8. old_path = bpy.path.abspath(image.filepath)
  9. base, ext = os.path.splitext(old_path)
  10.  
  11. # Skip if there's no extension (like generated images)
  12. if ext:
  13. new_path = base + ".webp"
  14.  
  15. # Optional: only replace if the .webp file exists
  16. if os.path.exists(new_path):
  17. image.filepath = bpy.path.relpath(new_path)
  18. count += 1
  19. else:
  20. print(f"⚠️ Skipped (no webp found): {old_path}")
  21.  
  22. print(f"✅ Replaced {count} image(s) with .webp versions.")
Advertisement
Add Comment
Please, Sign In to add comment