OK that’s what I found and managed to scrap together a small script by using other peoples similar code and the blender python api which, frankly - is not very helpful or clear in explaining exactly what data you are retrieving and how to modify it with the various methods etc listed …
Feel free to use the script below. It simply takes all the duplicate images - eg… ending in .001 usually- in a blend file and sets the user count to 0 for them so that on a save and reload they are gone YAYY!.
It also searches the materials in the file and every time it finds an ImageTexture node in a material it relinks the correct image back so that after deleting the duplicates you aren’t left with broken materials!
Todo: for someone with more blender2.6+ python experience you could also add a new loop to the code that would loop through the materials that don’t use nodes such as the blender internal render mats and find images/environment textures and fix the broken names as well. Right now it only does this for cycles mats that use nodes…
for i in bpy.data.images:
if iname[-4] == "." and iname[0:-4] in ilist:
for mat in bpy.data.materials:
for node in mat.node_tree.nodes:
#print("node" , node.bl_idname)
if node.bl_idname == "ShaderNodeTexImage":
if node.image :
if node.image.name[-4] == "." and node.image.name[0:-4] in ilist:#and node.image.name in ilist_dup:
print("node" , node.bl_idname , "replacing",node.image.name,"with",node.image.name[0:-4])