diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-12-10 09:38:00 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-12-10 09:38:00 +0400 |
commit | 65f3b93f144699fa4aafa46c7e226aa1390b7239 (patch) | |
tree | 1a9599589c98d9e17631844fd011463031fe59cd /release/scripts/modules | |
parent | 99d893bb89a96dd0d6cb9410b12928e7ade4b565 (diff) | |
parent | a88b29c062f32514e4414bfd4006f7b348077a42 (diff) |
svn merge ^/trunk/blender -r42521:42550
Diffstat (limited to 'release/scripts/modules')
-rw-r--r-- | release/scripts/modules/bpy_extras/image_utils.py | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/release/scripts/modules/bpy_extras/image_utils.py b/release/scripts/modules/bpy_extras/image_utils.py index 52050b08bc7..7d409510c85 100644 --- a/release/scripts/modules/bpy_extras/image_utils.py +++ b/release/scripts/modules/bpy_extras/image_utils.py @@ -65,19 +65,45 @@ def load_image(imagepath, # 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,11 +129,9 @@ def load_image(imagepath, if os.path.exists(nfilepath): return _image_load(nfilepath) + # None of the paths exist so return placeholder if place_holder: - image = bpy.data.images.new(bpy.path.basename(imagepath), 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 |