As soon as I add in either of these lines:

(set! num-layers (car (gimp-image-get-layers newimage)))
(set! layerIDs (cadr (gimp-image-get-layers newimage)))


I get batch command execution errors.

The full script is:

(define (batch-save-as-xcf pattern)
  (let* (
      (filelist (cadr (file-glob pattern 1)))
      (fileparts)
  (xcfname)
      (filename)
      (image)
  (newimage)
      (drawable)
      )
 (gimp-message-set-handler 2)
(gimp-message "Preparing to act on the following files")
(gimp-message pattern)

(while (pair? filelist)
 ; set filename to the name of the current file in the glob
(set! filename (car filelist))
(gimp-message "The current file is: ")
    (gimp-message filename)

; set xcfname by tokenizing on "." and taking everything but the last part
(set! fileparts (strbreakup filename "."))
(set! fileparts (butlast fileparts))
(set! xcfname (string-append (unbreakupstr fileparts ".") ".xcf"))
(gimp-message "The new filename will be: ")
(gimp-message xcfname)
 ; set image from the file, and then get the first layer and set it to
newimage
(gimp-message "Loading File.")
(set! newimage (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
 (set! num-layers (car (gimp-image-get-layers newimage)))
(set! layerIDs (cadr (gimp-image-get-layers newimage)))

; set drawable to the newimage
(gimp-message "Setting the Drawable.")

(set! drawable (car (gimp-image-flatten newimage)))


; save the drawable from newimage as xcfname
  (gimp-message "Saving the new file.")
  (gimp-file-save RUN-NONINTERACTIVE newimage drawable xcfname xcfname)

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




Date: Sun, 06 Jun 2010 17:46:15 -0400
From: saulgo...@flashingtwelve.brickfilms.com
Subject: Re: [Gimp-user] Script-Fu for batch image conversion
To: gimp-user@lists.XCF.Berkeley.EDU
Message-ID:
       <20100606174615.awibbw09xk44k...@flashingtwelve.brickfilms.com>
Content-Type: text/plain;       charset=ISO-8859-1;     DelSp="Yes";
       format="flowed"

Quoting Dillon <dillonontheco...@gmail.com>:

> The reason I'm writing my own script-fu, rather than using Daves Batch
> Processor, is that my TIF files are multi-page, and when I load the image
> and flatten it to a drawable, I end up with both pages flattened into one
> drawable.  I only want one of the pages (I think the first).
>
> I need to find a way to select that page (which I assume is turned into a
> layer when the TIF is loaded), and just set that layer to be my drawable.

In that case, you were on the right track originally with using
'gimp-image-get-layers' (I am also assuming multi-page TIFFs load as
separate layers). However, you had incorrectly handled the value
returned by the function.

'gimp-image-get-layers' returns returns a list containing two
elements: the number of layers in the image and an array of the
layerIDs of those layers:

  (set! num-layers (car (gimp-image-get-layers image)))
  (set! layerIDs (cadr (gimp-image-get-layers image)))

You can obtain the layerID of the top layer with:

  (set! top-layer (vector-ref layerIDs 0))

The next down with:

  (set! next-layer (vector-ref layerIDs 1))

And so on:

  (set! bottom-layer (vector-ref layerIDs (- num-layers 1)))


If you know the position of the layer you wish to keep (the TIFF
page), you can then remove all of the other layers from the image with:

  (set! pos 0)
  (while (< pos num-layers)
    (unless (= pos TIFFpage)
      (gimp-image-remove-layer image (vector-ref layerIDs pos))
      )
    (set! i (+ i 1))
    )
_______________________________________________
Gimp-user mailing list
Gimp-user@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-user

Reply via email to