0

I downloaded a script to batch convert images to a .gbr and It's outdated and doesn't work with current version of GIMP. I don't know much about script-fu so when I got the first error "Error: set!: unbound variable: a" I did a search and found out that after GIMP 2.4 when initially defining variables you use "define" and not "set!".

I fixed all those instances and then got this new error "Error: eval: unbound variable: newimage". The error is quite vague on which reference of "newimage" it's talking about so I started changing declared variables from "define" back to "set!" cause I know that give me an error and that means the code hasn't executed the reference of "newimage" it has a problem with.

I changed "filename2" and got the "set!" error which is at the end of the block so I know its something is going in the last block.

I really don't want to go through the script-fu tutorials in the GIMP manual and learn about to maybe get my answer after understanding the code better although I already read some (the only code Im familiar with is C++). I also have a digital painting course I need to get back to so hopefully there is someone who can shed light on this issue. Thanks in advance.

    (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" "")


   
Magoo
  • 77,302
  • 8
  • 62
  • 84
Gyorio
  • 1
  • 2

1 Answers1

0

It would be easier if you pointed us to a source of the original script so we can suggest how you can get it to be compatible with the current version of GIMP.

Just change all the "defines" to "set!" is demonstrably not true so I went and found the original here: https://www.deviantart.com/kward1979uk/art/GIMP-Batch-brush-converter-31179822

You now have to have assigned variables before trying to re-assign a value to them using set!, which is done simply by setting them to something inside the let* section at the top. Also the while condition needs a test for non-null now.

(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)))
            )
paynekj
  • 323
  • 2
  • 5
  • Just change all the "defines" to "set!" and you have the original. That's literally all I changed so no need to upload original. On another note, I just found a .gbr on my desktop so it's outputting even with the error. I Don't know whats going on. Havent checked the file size nor have I tried putting in brushes folder yet. – Gyorio Feb 03 '21 at 00:06
  • Your code almost worked.... The problem now is that it created a .gbr for every png! – Gyorio Feb 07 '21 at 18:10