1

I'm using the following script to batch-process some image files with GIMP script-fu:

       (let* ((filename (car filelist))
              (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
              (imagelayer (car (gimp-image-get-layers image)))
              (bglayer (car (gimp-layer-new image 8400 5939 1 ""bg"" 100 LAYER-MODE-NORMAL))))
         (gimp-image-add-layer image bglayer 1)
         (gimp-layer-set-offsets (car (gimp-image-get-layers image)) 0 870)

Line 2 loads an image, line 3 gets the single layer of the image, line 4 creates a new background layer, line 5 adds the new layer to the image, and line 6 sets the offsets of the image layer.

However line 6 throws the following error:

GIMP-Error: Calling error for procedure 'gimp-layer-set-offsets':
Procedure 'gimp-layer-set-offsets' has been called with an invalid ID for 
argument 'layer'. Most likely a plug-in is trying to work on a layer that 
doesn't exist any longer.

I tried to change line 6 to the following, but I'm getting the same error:

         (gimp-layer-set-offsets imagelayer 0 870)

Strange thing is, the error does not appear always, sometimes the routine runs through without an error.

Is this a GIMP bug or an error in my script?

Jonas Sourlier
  • 13,684
  • 16
  • 77
  • 148

2 Answers2

1

A possible explanation is that the hardcoded layer type (1: RGBA-IMAGE) is not compatible with the image type (for instance, color-indexed(*)...) so your layer is not added to the image. Try to either force the image type (gimp-image-convert-rgb), or set the layer type to something compatible with the image type (gimp-image-base-type, or reuse the type of the existing layer).

(*) AFAIK there are (rare) grayscale JPG, and there are more frequent color-indexed PNGs, and then there are GIFs.

xenoid
  • 8,396
  • 3
  • 23
  • 49
1

gimp-image-get-layers returns a list of 2 values, the number of layers and a list of the layer ids.

By using car, you have selected to use the number of layers value as the layer id.

Try using gimp-image-get-active-layer instead.

paynekj
  • 323
  • 2
  • 5