开发者

Why can't GIMP handle this script?

I have this script as an .scm in Gimp:

;MIT license.

(define (script-fu-export-layers img drw path outnameformat)
; credit to Vijay Mathew on Stack Overflow for the expand keywords function
  (let ((expand-keywords (lambda(format tokens)
    (let loop ((slist (string->list string))
               (in-replace-mode #f)
               (result ""))
      (if (not (null? slist))
          (let ((c (car slist)))
            (cond (in-replace-mode
                   (let ((token (car (cdr (assoc c tokens)))))
                     (loop (cdr slist) #f (string-append result token))))
                  ((char=? c #\~)
                   (loop (cdr slist) #t result))
                  (else
                   (loop (cdr slist) #f (
                      string-append result (make-string 1 c))))))
          result)))))
  (for-each (lambda (layer)
    (let* (
        (name (expand-keywor开发者_高级运维ds outnameformat '(
          (#\i (car(gimp-image-get-name img)))
          (#\l (car(gimp-drawable-get-name layer))))))
        (outpath (string-append path "/" name)))
      (gimp-file-save RUN-NONINTERACTIVE img layer outpath name)
  )) (vector->list(cadr (gimp-image-get-layers img)))))
)

(script-fu-register
  "script-fu-export-layers"
  "L_ayers"
  "Export all layers as individual files."
  "Stuart P. Bentley <stuart@testtrack4.com>"
  "Copyright 2011 Stuart P. Bentley"
  "June 28, 2011"
  "*"
  SF-IMAGE       "The Image"         0
  SF-DRAWABLE    "The Layer"         0
  SF-DIRNAME     "Output directory"  ""
  SF-STRING      "Filename Format (~i = image name, ~l = layer name)"
                                                          "~i-~l.png"
)
(script-fu-menu-register "script-fu-export-layers" "<Image>/File/E_xport")

With the comment at the top of the file, the script doesn't load at all. When the comment is removed, GIMP throws an error when refreshing scripts that "Error while loading C:\Users\Stuart.gimp-2.6\scripts\export-layers.scm: Error: unmatched parentheses: 1". I don't know what that's about, since it parses fine when I run it on Codepad (it breaks at the script-fu-register point).


This behavior is consistent with what would happen if the line endings were missing (the comments commenting out all subsequent text). Check to make sure your editor isn't doing something ridiculous like saving your file with CR line endings on Windows.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜