【问题标题】:GIMP "Error: eval: unbound variable: newimage" When when executing scriptGIMP“错误:eval:未绑定变量:newimage”执行脚本时
【发布时间】:2021-02-01 06:51:27
【问题描述】:

我下载了一个脚本来将图像批量转换为 .gbr,但它已经过时并且不适用于当前版本的 GIMP。我对 script-fu 了解不多,所以当我收到第一个错误“错误:设置!:未绑定变量:a”时,我进行了搜索,发现在 GIMP 2.4 之后最初定义变量时使用“定义”而不是“设置!”。

我修复了所有这些实例,然后出现了这个新错误“错误:评估:未绑定变量:新图像”。该错误对于它所谈论的“newimage”的引用非常模糊,因此我开始将声明的变量从“define”更改回“set!”因为我知道给我一个错误,这意味着代码没有执行它有问题的“newimage”的引用。

我更改了“filename2”并获得了“set!”块末尾的错误,所以我知道它在最后一个块中发生了一些事情。

我真的不想通过 GIMP 手册中的 script-fu 教程并了解可能在更好地理解代码后得到我的答案,尽管我已经阅读了一些(我熟悉的唯一代码是 C++)。我还有一门数字绘画课程,我需要回去学习,所以希望有人可以阐明这个问题。提前致谢。

    (define (brush-batch load opt name filename spacing location)
(define a(cond (( equal? opt 0 ) ".jpg" )
               (( equal? opt 1 ) ".bmp" )
               (( equal? opt 2 ) ".xcf" )
               (( equal? opt 3 ) ".png" )
               (( equal? opt 4 ) ".gif" )))

(let* ((filelist (cadr (file-glob (string-append load "\\*" a)  1))) 
       (s 1))
(while filelist
    (let* (
        (loadfile (car filelist))
        (image (car (gimp-file-load RUN-NONINTERACTIVE loadfile loadfile)))
        )


(gimp-image-flatten image)
(define drawable (gimp-image-get-active-drawable image))
(if (= 1 (car (gimp-selection-is-empty image)))
(gimp-selection-all image))
(gimp-displays-flush)
(gimp-edit-copy (car drawable) )
(define selection-bounds (gimp-selection-bounds image))
(define sx1 (cadr selection-bounds))
(define sy1 (caddr selection-bounds))
(define sx2 (cadr (cddr selection-bounds)))
(define sy2 (caddr (cddr selection-bounds)))
(gimp-image-delete image)
(define swidth  (- sx2 sx1))
(define sheight (- sy2 sy1))
(define newimage (gimp-image-new swidth sheight 0))
(define newlayer (gimp-layer-new (car newimage) swidth sheight 1 "newlayer" 100 0))
(gimp-image-add-layer (car newimage) (car newlayer) 0)
(gimp-drawable-fill (car newlayer) 3)
(gimp-edit-paste (car newlayer) 0 )
(gimp-image-flatten (car newimage))
(define active (gimp-image-get-active-drawable (car newimage)))
(gimp-desaturate (car active))
(gimp-image-convert-grayscale (car newimage))
(gimp-displays-flush)
(gimp-selection-all (car newimage))
(define filename2 (string-append location "/" filename (string-append (number->string s))".gbr"
))
(file-gbr-save 1 (car newimage) (car active) filename2 (string-append name (number->string s)) spacing (string-append name (number->string s))))
(define s (+ s 1))
(gimp-image-delete (car newimage))
(define filelist (cdr filelist))))
)
(script-fu-register "brush-batch"
            "<Toolbox>/Xtns/Script-Fu/Gimp-talk.com/Brush-batch..."
            "turns a folder of files into brush's works with jpg, bmp, xcf, png and gif"
            "Karl Ward"
            "Karl Ward"
            "April 2006"
            ""
            
            SF-DIRNAME    "Load from" ""
            SF-OPTION     "File Type"'("jpg" "bmp""xcf""png""gif")

                SF-STRING     "Brush Name" "name"
                SF-STRING     "File Name" "filename"
                SF-ADJUSTMENT "spacing"         '(25 0 1000 1 1 1 0)
                SF-DIRNAME    "SAVE TO FOLDER" "")


   

【问题讨论】:

    标签: gimp script-fu


    【解决方案1】:

    如果您向我们指出原始脚本的来源会更容易,这样我们就可以建议您如何使其与当前版本的 GIMP 兼容。

    只需将所有“定义”更改为“设置!”显然不是真的,所以我在这里找到了原文:https://www.deviantart.com/kward1979uk/art/GIMP-Batch-brush-converter-31179822

    您现在必须先分配变量,然后再尝试使用 set! 为它们重新分配值,只需将它们设置为顶部的 let* 部分中的内容即可。此外,while 条件现在需要测试非空。

    (define (brush-batch load opt name filename spacing location)
      (let* (
            (a
              (cond 
                (( equal? opt 0 ) ".jpg" )
                (( equal? opt 1 ) ".bmp" )
                (( equal? opt 2 ) ".xcf" )
                (( equal? opt 3 ) ".png" )
                (( equal? opt 4 ) ".gif" )
              )
            )
            (filelist (cadr (file-glob (string-append load "\\*" a)  1)))
            (s 1)
            (drawable 0) (selection-bounds 0) (sx1 0) (sx2 0) (sy1 0) (sy2 0) (swidth 0) (sheight 0)
            (newimage 0) (newlayer 0) (active 0) (filename2 "")
        )
        (while (not (null? filelist))
          (let* (
                  (loadfile (car filelist))
                  (image (car (gimp-file-load RUN-NONINTERACTIVE loadfile loadfile)))
                )
    

    【讨论】:

    • 只需将所有“定义”更改为“设置!”你有原件。这就是我所做的全部更改,因此无需上传原件。另一方面,我刚刚在我的桌面上找到了一个 .gbr ,因此即使出现错误它也会输出。我不知道发生了什么事。还没有检查文件大小,也没有尝试放入画笔文件夹。
    • 你的代码几乎可以工作了......现在的问题是它为每个 png 创建了一个 .gbr!
    猜你喜欢
    • 2018-09-15
    • 2014-04-08
    • 1970-01-01
    • 2019-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多