+ (let (image-directory image-directory-load-path)
+ ;; Check for images in image-load-path or load-path.
+ (let ((img image)
+ (dir (or
+ ;; Images in image-load-path.
+ (gmm-image-search-load-path image) ;; "gmm-" prefix!
+ ;; Images in load-path.
+ (locate-library image)))
+ parent)
+ ;; Since the image might be in a nested directory (for
+ ;; example, mail/attach.pbm), adjust `image-directory'
+ ;; accordingly.
+ (when dir
+ (setq dir (file-name-directory dir))
+ (while (setq parent (file-name-directory img))
+ (setq img (directory-file-name parent)
+ dir (expand-file-name "../" dir))))
+ (setq image-directory-load-path dir))
+
+ ;; If `image-directory-load-path' isn't Emacs' image directory,
+ ;; it's probably a user preference, so use it. Then use a
+ ;; relative setting if possible; otherwise, use
+ ;; `image-directory-load-path'.