diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-04-05 04:30:32 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-04-05 04:30:32 +0400 |
commit | 98752a1f3025a138b5a2f70f60a2cca1e89d2f66 (patch) | |
tree | 9d6adf01f7fa74d7e995675ff466532167d8ba49 /release/scripts/modules/bpy_extras/image_utils.py | |
parent | dee2f0c9ac8312ff71241d86591adb8f9b06c53a (diff) |
py api additions needed for fixing [#34864].
- add rna property 'as_bytes' method so you can get a string property as python bytes (bypass encoding).
- make bpy.path.abspath/relpath compatible with bytes.
- add 'relpath' option to bpy_extras.image_utils.load_image(), so you can load an image relative to a path.
Diffstat (limited to 'release/scripts/modules/bpy_extras/image_utils.py')
-rw-r--r-- | release/scripts/modules/bpy_extras/image_utils.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/release/scripts/modules/bpy_extras/image_utils.py b/release/scripts/modules/bpy_extras/image_utils.py index 36994d3fddd..5c63ce1218e 100644 --- a/release/scripts/modules/bpy_extras/image_utils.py +++ b/release/scripts/modules/bpy_extras/image_utils.py @@ -31,6 +31,7 @@ def load_image(imagepath, ncase_cmp=True, convert_callback=None, verbose=False, + relpath=None, ): """ Return an image from the file path with options to search multiple paths @@ -57,6 +58,8 @@ def load_image(imagepath, convert it to a PNG and return the PNG's path. For formats blender can read, simply return the path that is given. :type convert_callback: function + :arg relpath: If not None, make the file relative to this path. + :type relpath: None or string :return: an image or None :rtype: :class:`bpy.types.Image` """ @@ -100,6 +103,12 @@ def load_image(imagepath, if place_holder and image is None: image = _image_load_placeholder(path) + if image: + if relpath is not None: + # make relative + from bpy.path import relpath as relpath_fn + image.filepath_raw = relpath_fn(path, start=relpath) + return image # ------------------------------------------------------------------------- |