我正在尝试为GIMP 2.8编写一个方案脚本,它将调整大小并重命名/复制文件。作为其中的一部分,我想根据脚本中的布尔值设置更改输出文件名。
然而,我的条件却被忽略了。以下是脚本的摘录(基于this thread中的一个):(define (script-fu-batch-resize globexp globext src)
(define (resize-img n f newx suffix srcdir removetailingunderscore)
(let* ((fname (car f))
;get path, short name + extension (remember to remove source dir to REPLACE with suffix!)
(fullname (car (last (strbreakup fname "\\"))))
(filepath (substring fname 0 (- (string-length fname) (string-length (string-append srcdir fullname)))))
(name0 (car (strbreakup fullname ".")))
(name1 (substring name0 0 (- (string-length name0) 1)) )
(when
(> 1 0)
(
(name0 (name1) )
)
)
(extension (cadr (strbreakup fullname ".")))
(img (car (gimp-file-load 1 fname fname))))
(gimp-image-undo-disable img)
(let*
(
(oldx (car (gimp-image-width img)))
(oldy (car (gimp-image-height img)))
(newy (/ oldy (/ oldx newx)))
)
(gimp-image-scale img newx newy) ;changed for Gimp v2.6
)
(gimp-file-save 1 img (car (gimp-image-get-active-drawable img)) (string-append filepath suffix "\\" name1 "." extension) fname)
(gimp-image-delete img)
)
(if (= n 1) 1 (resize-img (- n 1) (cdr f) newx suffix srcdir removetailingunderscore))
)
(define sourcepattern (string-append globexp src globext))
(define files (file-glob sourcepattern 0)) ;changed for Gimp v2.6
(resize-img (car files) (car (cdr files)) 55 "micro" src 1)
)
我尝试过使用when
和if
- 否则无论条件块内部没有任何语句被执行(即如果我在if中使用相同的true和false语句,也不会被执行)。我的条件完全被忽略但我不知道为什么。 GIMP不会报告任何语法错误。
我怀疑在define
语句中我不能有条件,除非有一个在它下面正常工作。
任何人都可以看到有什么问题吗?为什么我的条件会被忽略?
答案 0 :(得分:5)
when
表达式有几个问题:
(> 1 0)
始终为真,因此无用set!
when
表达式移到let*
的变量定义部分之外,并将其作为let*
你需要做的是这样的事情:
(define (script-fu-batch-resize globexp globext src)
(define (resize-img n f newx suffix srcdir removetailingunderscore)
(let* ((fname (car f))
(fullname (car (last (strbreakup fname "\\"))))
(filepath (substring fname 0 (- (string-length fname) (string-length (string-append srcdir fullname)))))
(name0 (car (strbreakup fullname ".")))
(name1 (substring name0 0 (- (string-length name0) 1)))
(extension (cadr (strbreakup fullname ".")))
(img (car (gimp-file-load 1 fname fname))))
(when (> 1 0)
(set! name0 name1))
<rest of the body>)))