2

我正在尝试用 GIMP Script-Fu 做最简单的事情,但我一定缺少一些基本的东西。

我制作了一个 100x100 的灰度图像和一个 200x200 的黑色图像,我正在尝试将灰色方块复制到黑色方块上。然而,输出只是一个黑色方块(找不到灰色方块)。这是我正在尝试做的更多涉及的事情的最小测试用例(涉及 2 个单独的图像),但我将一次解决一个问题。

根据我自己的故障排除,似乎问题可能出在复制/粘贴步骤中,但不幸的是,我不太了解 Script-Fu 中 (gimp-edit-copy) 和 (gimp-edit-paste) 的文档过程浏览器。

我哪里出错了?

谢谢

; 1) save this file as `$HOME/.gimp-2.8/scripts/copy-test.scm'
; 2) $ gimp -i -b '(copy-test)' -b '(gimp-quit 0)'
; 3) check `out.png' for result

(define (copy-test)
  (let* (; create 100x100 image img-a & 200x200 image img-b
         (img-a (car (gimp-image-new 100 100 RGB)))
         (img-b (car (gimp-image-new 200 200 RGB)))

         ; make new layers for each image
         (layer-a0 
           (car (gimp-layer-new 
                  img-a 100 100 RGB-IMAGE "a0" 100 NORMAL-MODE)))
         (layer-b0 
           (car (gimp-layer-new 
                  img-b 200 200 RGB-IMAGE "b0" 100 NORMAL-MODE))))

    ; insert layers into appropriate images
    (gimp-image-insert-layer img-a layer-a0 0 0)
    (gimp-image-insert-layer img-b layer-b0 0 0)

    (let (; get the drawables for each image
          (draw-a (car (gimp-image-get-active-layer img-a)))
          (draw-b (car (gimp-image-get-active-layer img-b))))

      ; change img-a from black to gray
      (plug-in-exchange 
        RUN-NONINTERACTIVE img-a draw-a 0 0 0 128 128 128 1 1 1)

      ; copy/paste a (100px gray) onto b (200px black)
      (gimp-edit-copy draw-a)
      (gimp-edit-paste draw-b TRUE)

      ; save output to result.png
      (gimp-file-save 
        RUN-NONINTERACTIVE img-b draw-b "out.png" "out.png"))))

更新:

按照 xenoid 的建议,替换

(gimp-edit-paste draw-b TRUE)

(gimp-floating-sel-anchor
  (car (gimp-edit-paste draw-b TRUE)))

解决了这个问题。

4

2 回答 2

2

据我所知,您gimp-edit-paste创建了一个浮动选择(某种临时图层),但这不会改变draw-b,直到您“锚定”该浮动选择(gimp-floating-sel-anchor)。然后,gimp-file-save只保存图层而不是整个图像,因此您的粘贴不包含在文件中。

当您在脚本中创建图像时,将它们与“显示”( )相关联是有用的(至少在调试时gimp-display-new),这使得许多此类问题更加明显)。

于 2017-08-24T01:14:37.140 回答
-1
(define (copy-test)

(let* (; 创建 100x100 图像 img-a & 200x200 图像 img-b (img-a (car (gimp-image-new 100 100 RGB))) (img-b (car (gimp-image-new 200 200 RGB) )))

     ; make new layers for each image
     (layer-a0 
       (car (gimp-layer-new 
              img-a 100 100 RGB-IMAGE "a0" 100 NORMAL-MODE)))
     (layer-b0 
       (car (gimp-layer-new 
              img-b 200 200 RGB-IMAGE "b0" 100 NORMAL-MODE))))

; insert layers into appropriate images
(gimp-image-insert-layer img-a layer-a0 0 0)
(gimp-image-insert-layer img-b layer-b0 0 0)

(let (; get the drawables for each image
      (draw-a (car (gimp-image-get-active-layer img-a)))
      (draw-b (car (gimp-image-get-active-layer img-b))))

  ; change img-a from black to gray
  (plug-in-exchange 
    RUN-NONINTERACTIVE img-a draw-a 0 0 0 128 128 128 1 1 1)

  ; copy/paste a (100px gray) onto b (200px black)
  (gimp-edit-copy draw-a)
  (gimp-floating-sel-anchor (car (gimp-edit-paste draw-b TRUE)))

  ; save output to result.png
  (gimp-file-save 
    RUN-NONINTERACTIVE img-b draw-b "out.png" "out.png"))))
于 2021-06-26T00:21:12.333 回答