Scriptfu 没有按正确的顺序执行,为什么?

发布于 2024-11-03 05:32:11 字数 652 浏览 6 评论 0原文

我正在尝试为 GIMP 编写一个基本脚本,但它似乎无法正常工作。在我做出选择后,它应该遵循以下顺序:降低活动层,将选择范围扩大 2px,用前景色填充,升高活动层。最终产品应该是顶层线条下方的纯色。但是使用我编写的代码,它会跳过活动层,但会在顶层而不是下面的层上进行洪水填充。这是我的代码:

(define (quick-fill image drawable)
  (gimp-undo-push-group-start image)
  (let* ((layer (car (gimp-image-get-active-layer image))))
    (gimp-selection-grow image 2)
    (gimp-image-set-active-layer image (aref (cadr (gimp-image-get-layers image)) 1))
    (gimp-bucket-fill drawable FG-BUCKET-FILL NORMAL-MODE 100 0 FALSE 0 0)
    (gimp-image-set-active-layer image (aref (cadr (gimp-image-get-layers image)) 0)))
  (gimp-undo-push-group-end image)
  (gimp-displays-flush))

I'm trying to write a basic script for GIMP but it doesn't seem to want to work right. It should follow this order after I make my selection: Lower active layer, expand selection 2px, floodfill w/ foreground color, raise active layer. The final product should be a solid color beneath my lines on the top layer. But with the code i wrote, it jumps active layers, but floodfills on the top layer and not the one below. Here is the code I have:

(define (quick-fill image drawable)
  (gimp-undo-push-group-start image)
  (let* ((layer (car (gimp-image-get-active-layer image))))
    (gimp-selection-grow image 2)
    (gimp-image-set-active-layer image (aref (cadr (gimp-image-get-layers image)) 1))
    (gimp-bucket-fill drawable FG-BUCKET-FILL NORMAL-MODE 100 0 FALSE 0 0)
    (gimp-image-set-active-layer image (aref (cadr (gimp-image-get-layers image)) 0)))
  (gimp-undo-push-group-end image)
  (gimp-displays-flush))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅笑轻吟梦一曲 2024-11-10 05:32:11

如果您尝试创建一个过滤器,通过在下面的图层上在对象后面进行填充,在当前图层上的对象周围创建 2 像素边框(至少看起来您正在尝试这样做),请尝试这:

(define (quick-fill image)
  (gimp-undo-push-group-start image)
  (gimp-selection-grow image 2)
  (gimp-image-set-active-layer image (aref (cadr (gimp-image-get-layers image)) 1))
  (let* ((active-drawable (car (gimp-image-get-active-drawable image))))
    (gimp-bucket-fill active-drawable FG-BUCKET-FILL NORMAL-MODE 100 0 FALSE 0 0)
    (gimp-image-set-active-layer image (aref (cadr (gimp-image-get-layers image)) 0)))
  (gimp-undo-push-group-end image)
  (gimp-displays-flush))

一些注意事项:

1)您从未在 let* 部分中使用 layer 变量,因此我已将其删除。

2) Gimp 不会对活动图层进行绘制、填充或执行任何操作...而是在活动图层上工作。如果当您希望在下面的图层上填充时,您在顶层上得到填充,那么这意味着您正在传递顶层的可绘制对象,因此它将填充在顶层上...切换活动图层到下面的图层不会更改传入的可绘制对象的值。因此,在此修改中,我在 let* 部分创建了一个新的 active-drawable 变量,该变量在之后初始化为当前活动的可绘制对象您已将活动图层从顶层更改为下面的图层。这样,您将填充下面图层的可绘制对象,而不是顶层的原始传入可绘制对象。事实上,您根本不需要传入可绘制参数,因为您可以从活动层获取新的可绘制参数(这就是此修改中所做的)。

If you're trying to make a filter that makes a 2-pixel border around an object on the current layer by making a fill behind it on the layer below (at least that's what it appears you're trying to-do), try this:

(define (quick-fill image)
  (gimp-undo-push-group-start image)
  (gimp-selection-grow image 2)
  (gimp-image-set-active-layer image (aref (cadr (gimp-image-get-layers image)) 1))
  (let* ((active-drawable (car (gimp-image-get-active-drawable image))))
    (gimp-bucket-fill active-drawable FG-BUCKET-FILL NORMAL-MODE 100 0 FALSE 0 0)
    (gimp-image-set-active-layer image (aref (cadr (gimp-image-get-layers image)) 0)))
  (gimp-undo-push-group-end image)
  (gimp-displays-flush))

A couple notes:

1) You never use the layer variable in your let* section, so I've removed it.

2) Gimp doesn't draw or fill or do anything with the active layer ... rather it works on the active drawable. If you're getting a fill on the top layer when you want it on the layer below, then that means you're passing in the drawable for the top layer, so it's going to fill on the top layer ... switching the active layer to the layer below doesn't change the value of the passed-in drawable. So in this modification, I've created a new active-drawable variable in the let* section that gets initialized to the currently active drawable after you've changed the active layer from the top-layer to the layer underneath. That way you're filling the drawable that is the layer below, not the original passed-in drawable that is the top-layer. In fact, you don't need to pass-in a drawable argument at all, since you can get the new drawable from the active layer (which is what's done in this modification).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文