GIMP script-fu(方案)从一个图像复制/粘贴到另一个图像

时间:2017-08-23 23:31:58

标签: gimp script-fu

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

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

根据我自己的故障排除,似乎问题可能出在复制/粘贴步骤中,但不幸的是我无法理解(gimp-edit-copy)和(gimp-edit-paste)的文档。 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)))

修复了问题。

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:-1)

(define (copy-test)

(let* (; 创建 100x100 图像 img-a & 200x200 图像 img-b (img-a(汽车(gimp-image-new 100 100 RGB))) (img-b (汽车 (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"))))