[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [42545] trunk/blender/release/scripts/ modules/bpy_extras/image_utils.py: fix for error in bpy_extras.image_utils. load_image() when the image file exists but cant be read ( wrong permissions for eg).
Campbell Barton
ideasman42 at gmail.com
Sat Dec 10 02:01:23 CET 2011
Revision: 42545
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42545
Author: campbellbarton
Date: 2011-12-10 01:01:22 +0000 (Sat, 10 Dec 2011)
Log Message:
-----------
fix for error in bpy_extras.image_utils.load_image() when the image file exists but cant be read (wrong permissions for eg).
Modified Paths:
--------------
trunk/blender/release/scripts/modules/bpy_extras/image_utils.py
Modified: trunk/blender/release/scripts/modules/bpy_extras/image_utils.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy_extras/image_utils.py 2011-12-10 01:00:12 UTC (rev 42544)
+++ trunk/blender/release/scripts/modules/bpy_extras/image_utils.py 2011-12-10 01:01:22 UTC (rev 42545)
@@ -65,19 +65,45 @@
# TODO: recursive
+ # -------------------------------------------------------------------------
+ # Utility Functions
+
+ def _image_load_placeholder(path):
+ name = bpy.path.basename(path)
+ if type(name) == bytes:
+ name = name.decode('utf-8', "replace")
+ image = bpy.data.images.new(name, 128, 128)
+ # allow the path to be resolved later
+ image.filepath = path
+ image.source = 'FILE'
+ return image
+
def _image_load(path):
import bpy
if convert_callback:
path = convert_callback(path)
- image = bpy.data.images.load(path)
+ try:
+ image = bpy.data.images.load(path)
+ except RuntimeError:
+ image = None
if verbose:
- print(" image loaded '%s'" % path)
+ if image:
+ print(" image loaded '%s'" % path)
+ else:
+ print(" image load failed '%s'" % path)
+ # image path has been checked so the path could not be read for some
+ # reason, so be sure to return a placeholder
+ if place_holder:
+ image = _image_load_placeholder(path)
+
return image
+ # -------------------------------------------------------------------------
+
if verbose:
print("load_image('%s', '%s', ...)" % (imagepath, dirname))
@@ -103,14 +129,9 @@
if os.path.exists(nfilepath):
return _image_load(nfilepath)
+ # None of the paths exist so return placeholder
if place_holder:
- name = bpy.path.basename(imagepath)
- if type(name) == bytes:
- name = name.decode('utf-8', "replace")
- image = bpy.data.images.new(name, 128, 128)
- # allow the path to be resolved later
- image.filepath = imagepath
- return image
+ return _image_load_placeholder(imagepath)
# TODO comprehensiveImageLoad also searched in bpy.config.textureDir
return None
More information about the Bf-blender-cvs
mailing list