GIMP script-fu中参数'layer'的ID无效

问题描述 投票:0回答:2

我正在使用以下脚本使用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)

第2行加载图像,第3行获取图像的单个图层,第4行创建新的背景图层,第5行将新图层添加到图像,第6行设置图像图层的偏移。

但是第6行会引发以下错误:

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.

我试图将第6行更改为以下内容,但我收到了同样的错误:

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

奇怪的是,错误并不总是出现,有时例程会没有错误地运行。

这是我的脚本中的GIMP错误还是错误?

gimp script-fu
2个回答
1
投票

可能的解释是硬编码图层类型(1:RGBA-IMAGE)与图像类型不兼容(例如,颜色索引(*)...)因此您的图层不会添加到图像中。尝试强制图像类型(gimp-image-convert-rgb),或将图层类型设置为与图像类型兼容的东西(gimp-image-base-type,或重用现有图层的类型)。

(*)AFAIK有(稀有)灰度JPG,并且有更频繁的颜色索引PNG,然后有GIF。


0
投票

gimp-image-get-layers返回2个值的列表,图层数和图层ID列表。

通过使用汽车,您已选择使用层数值作为图层ID。

请尝试使用gimp-image-get-active-layer。

© www.soinside.com 2019 - 2024. All rights reserved.