Post Reply 

Script-Fu Difficulties

Nov 22, 2011, 03:37
Post: #1
Script-Fu Difficulties
I've been racking my brain all day over the creation of a script. My ultimate goal is to take a folder of images and mass apply a scale2x filter to them and then save the results. So as not to accidentally destroy my original images (which I've already done several times due to GIMP loading random directories when no directory was specified in the script), I'm now setting it up to ask the user a directory to load from and save to.

I've devised what I have so far based off reading various other example scripts. This is my current version:

Code:
(define (batch-scale2x inDir outDir)

(let* ((filelist (cadr (file-glob (string-append inDir "\\*") 1))))
    (while (not (null? filelist))
        (let* ((filename (car filelist))
                        (short_filename (substring filename (+ (string-length inDir)

1) (- (string-length filename) 4)))
            (image (car (gimp-file-load RUN-NONINTERACTIVE filename

filename)))
            (drawable (car (gimp-image-get-active-layer image))))
        (python-fu-scale2x RUN-NONINTERACTIVE image drawable)
        (set! drawable (car (gimp-image-get-active-layer image)))
                
                (newfilename (string-append outDir "\\" short_filename ".png"))
        (gimp-file-save RUN-NONINTERACTIVE image drawable newfilename

newfilename)
        (gimp-image-delete image))
    (set! filelist (cdr filelist)))))

My issue right now is that I'm being told that "newfilename" is an unbounded variable so it errors while trying to save the resultant file. Any ideas on what I did wrong?
Find all posts by this user
Quote this message in a reply
Nov 22, 2011, 07:32 (This post was last modified: Nov 22, 2011 16:42 by paynekj.)
Post: #2
RE: Script-Fu Difficulties
I've re-arranged your code to make it easier for me to read:
Code:
(define (batch-scale2x inDir outDir)
  (let* (
         (filelist (cadr (file-glob (string-append inDir "\\*") 1)))
      )
      (while (not (null? filelist))
        (let* (
                (filename (car filelist))
                (short_filename (substring filename (+ (string-length inDir) 1) (- (string-length filename) 4)))
                (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
                (drawable (car (gimp-image-get-active-layer image)))
              )
              (python-fu-scale2x RUN-NONINTERACTIVE image drawable)
              (set! drawable (car (gimp-image-get-active-layer image)))
                
              (newfilename (string-append outDir "\\" short_filename ".png"))
              (gimp-file-save RUN-NONINTERACTIVE image drawable newfilename newfilename)
              (gimp-image-delete image))
              (set! filelist (cdr filelist))
      )
   )
)
Doing that I can see that you have got the first use of "newfilename" outside the definition section of the let* block for the while loop. Try moving that line to immediately under the "(drawable (car (gimp-image....." line.
It also appears that you have a missing parenthesis.

Kevin
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Request for script chlebna 1 128 Sep 13, 2017 09:35
Last Post: ythgilb
  Request for script - Guillotine + Watermark sunslick 1 194 Sep 4, 2017 08:51
Last Post: ythgilb
  Script-fu: How to create new, addressable layer using gimp-floating-sel-to-layer Bertholom√§us 2 182 Aug 31, 2017 14:32
Last Post: Bertholomäus
  How to modify this script-fu? Zakary81 1 152 Aug 23, 2017 12:48
Last Post: paynekj
  Need help in running a gui script-fu via command line eyalzek 2 318 Oct 4, 2014 14:05
Last Post: eyalzek

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS