Gimptalk - Premier Gimp Community: script-fu file-glob not returning value - Gimptalk - Premier Gimp Community

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

script-fu file-glob not returning value

#1 User is offline   AMaes 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 15-April 12

Posted 15 April 2012 - 11:14 PM

Hi,

I'm using copy paste of the example code from here:
http://www.gimp.org/...ls/Basic_Batch/

but I seem to be doing something wrong. My objective is to batch process a bunch of files using a filter i found for underwater images. I've tried both modifying the script I got and calling it using another function but I always get the same error:

MacBook-Pro:testImages twonius$ gimp -i -b '(batch-Scuba-mask "*.jpg")' -b '(gimp-quit 0)'
This is a development version of GIMP. Debug messages may appear here.

batch command experienced an execution error:
Error: ( : 32664) eval: unbound variable: filelist

plug-in 'script-fu' aborted before sending its procedure return values

here's my code:

(define (batch-Scuba-mask pattern)
(let* ( (filelist (cadr (file-glob pattern 1)) )))
(while (not (null? filelist))
(let* ((filename (car filelist))
(image (car (gimp-file-load RUN-NONINTERACTIVE
filename filename)))
(drawable (car (gimp-image-get-active-layer image))))
(script-fu-diving image 0 TRUE '(255 0 0))
(gimp-file-save RUN-NONINTERACTIVE
image drawable filename filename)
(gimp-image-delete image))
(set! filelist (cdr filelist))))

The folder i'm in does contain .jpg images, and I've changed the filenames to eliminate spaces.

script-fu-diving is working fine when I execute from gimp.

Considering I've only made a couple of modifications from the example script this must be something pretty simple.
0

#2 User is offline   paynekj 

  • Member
  • PipPip
  • Group: Members
  • Posts: 360
  • Joined: 01-June 05
  • LocationUK

Posted 16 April 2012 - 08:10 AM

You are right, it is a simple error.

Here's what I get when I format your code, without changing it's structure:
(Ignore the syntax highlighting, this forum is stupid and thinks that all code is written in C)
(define (batch-Scuba-mask pattern)
  (let* ( 
          (filelist (cadr (file-glob pattern 1)) )
        )
  )
  (while (not (null? filelist))
    (let* (
            (filename (car filelist))
            (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
            (drawable (car (gimp-image-get-active-layer image)))
          )
          (script-fu-diving image 0 TRUE '(255 0 0))
          (gimp-file-save RUN-NONINTERACTIVE image drawable filename filename)
          (gimp-image-delete image)
    )
    (set! filelist (cdr filelist))
  )
)

This layout shows me that you have defined 'filelist' within a let* block, BUT then gone on to use filelist OUTSIDE that block, where it isn't defined, hence the unbound variable error.

By moving the closing parenthesis for the let* to after the code, it should run OK:
(define (batch-Scuba-mask pattern)
  (let* ( 
          (filelist (cadr (file-glob pattern 1)) )
        )
    (while (not (null? filelist))
      (let* (
              (filename (car filelist))
              (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
              (drawable (car (gimp-image-get-active-layer image)))
            )
            (script-fu-diving image 0 TRUE '(255 0 0))
            (gimp-file-save RUN-NONINTERACTIVE image drawable filename filename)
            (gimp-image-delete image)
      )
      (set! filelist (cdr filelist))
    )
  )
)

Bearing in mind that this code will overwrite your existing files.

Kevin

This post has been edited by paynekj: 16 April 2012 - 08:15 AM

Kevin
0

#3 User is offline   AMaes 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 15-April 12

Posted 16 April 2012 - 08:51 AM

Thanks a lot!

It took me a minute to see which let* you were talking about but once i ran it through a comparison I saw it.

In order to not overwrite the files can I just append the filename string with something like _fixed using:

string-append(filename "_fixed")

?

Otherwise they're copies exported from iPhoto anyway but it'd be nice in the future to know how to do this.

Thanks again,
Anton
0

#4 User is offline   paynekj 

  • Member
  • PipPip
  • Group: Members
  • Posts: 360
  • Joined: 01-June 05
  • LocationUK

Posted 16 April 2012 - 09:14 AM

Yes you can use string-append but if you do it the way you've shown: (set! filename (string-append filename "_fixed")) you'll end up with file names like my_image_file.jpg_fixed, which depending on your operating system, might not look like an image file any more if it relies on the file extension.

So you might be better prefixing the file name: (set! filename (string-append "fixed_" filename)) to get fixed_my_image_file.jpg

Kevin
Kevin
0

#5 User is offline   RobA 

  • Member
  • PipPip
  • Group: Members
  • Posts: 714
  • Joined: 05-November 07

Posted 18 April 2012 - 05:13 PM

If you really want to suffix the filename, use:

(set! filename (string-append (car (butlast (strbreakup filename "."))) "-mysuffix" "." (car (last (strbreakup filename ".")))))


-Rob A>
Posted Image
Fantasy Cartography and Mapping by RobA
0

#6 User is offline   AMaes 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 15-April 12

Posted 19 April 2012 - 07:13 PM

Thanks a lot! So far things are working like a charm.

The only issue i have now is that the file saved is the background. So none of the changes applied by the script I call are saved, the resulting image is just the original.

I've tried flattening the image but all I get is a black image at the end. Any ideas on how best to do this?

(define (batch-Scuba-mask pattern)
(let* ( (filelist (cadr (file-glob pattern 1)) ))
(while (not (null? filelist))
(let* (
(filename (car filelist))
(image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
(drawable (car (gimp-image-get-active-layer image)))
)

(script-fu-diving image drawable TRUE '(255 0 0) )

(set! filename (string-append (car (butlast (strbreakup filename "."))) "-fixed" "." (car (last (strbreakup filename ".")))))
(gimp-file-save RUN-NONINTERACTIVE image drawable filename filename)

(gimp-image-delete image)
)

(set! filelist (cdr filelist))
)
)
)


Sorry that the code isn't formatted. I've tried in Chrome and Safari and the button doesn't seem to be working on my computer.
0

#7 User is offline   paynekj 

  • Member
  • PipPip
  • Group: Members
  • Posts: 360
  • Joined: 01-June 05
  • LocationUK

Posted 23 April 2012 - 12:30 PM

Hopefully you will get to see this, as this site has become very unreliable AGAIN (let's try continuing over on GimpChat? gimpchat.com)

I'm having to guess where you got the script-fu-diving code: Here? http://registry.gimp.org/node/9694
But if it is, then that script creates new layers, so flattening after the call to script-fu-diving would certainly be necessary, and then you would need to get the id of the active layer again to pass to gimp-file-save.
Kevin
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic