GIMP script-fu (scheme) copy/paste 从一张图片到另一张图片

GIMP script-fu (scheme) copy/paste from one image to another

我正在尝试使用 GIMP Script-Fu 做最简单的事情,我一定是遗漏了一些基本的东西。

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

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

我哪里做错了?

谢谢

; 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)))

已解决问题。

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

当您在脚本中创建图像时,将它们关联到 "display"(gimp-display-new)很有用(至少在调试时如此),这使得许多此类问题更加明显) .

(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"))))