GIMP pythonfu 从当前图像中获取可绘制对象
我正在迭代所有打开的图像。我想对它们每个人应用阈值。由于阈值插件采用drawable
作为参数,因此每次更改图像时都应该更改drawable,至少这在编程上是有意义的。那么,如何从当前图像中获取可绘制对象呢?
for subimage in gimp.image_list():
pdb.gimp_undo_push_group_start(subimage)
pdb.gimp_drawable_set_image(drawable, subimage)
pdb.plug_in_randomize_pick(image,drawable,rndm_pct, rndm_rcount, randomize, seed)
spread_amount_x, spread_amount_y = 3, 3
# pdb.plug_in_spread(subimage,drawable,spread_amount_x, spread_amount_y)
pdb.plug_in_spread(subimage,drawable,spread_amount_x, spread_amount_y)
pdb.plug_in_gauss_rle2(subimage,drawable,horizontal, vertical)
# pdb.gimp_threshold(drawable, low_threshold, high_threshold)
pdb.gimp_undo_push_group_end(subimage)
请注意,注释掉的阈值将重复应用所选图像上的阈值,而不是循环中的所有图像。为了让我做到这一点,我必须切换到上下文中图像的可绘制部分。
I am iterating over all open images. I want to apply threshold on each of them. Since the threshold plugin takes drawable
as argument, the drawable should be changed every time the image is changed, at least that's what programatically makes sense. So, how do I get the drawable from the current image?
for subimage in gimp.image_list():
pdb.gimp_undo_push_group_start(subimage)
pdb.gimp_drawable_set_image(drawable, subimage)
pdb.plug_in_randomize_pick(image,drawable,rndm_pct, rndm_rcount, randomize, seed)
spread_amount_x, spread_amount_y = 3, 3
# pdb.plug_in_spread(subimage,drawable,spread_amount_x, spread_amount_y)
pdb.plug_in_spread(subimage,drawable,spread_amount_x, spread_amount_y)
pdb.plug_in_gauss_rle2(subimage,drawable,horizontal, vertical)
# pdb.gimp_threshold(drawable, low_threshold, high_threshold)
pdb.gimp_undo_push_group_end(subimage)
Note that the commented out threshold would repeatedly apply the threshold on the selected image rather than all the images looped in. In order for me to do that, I have to switch to the drawable of the image in context.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果图像只有一个图层,则:
或者
如果有多个图层,则可以使用索引(顶层为
layers[0]
,底层/背景图层为层[-1]
),或者您通过其他方式计算出该层,例如:PS:如果您冻结撤消堆栈(或者可能甚至完全禁用撤消)而不是执行撤消组。
If the images have a single layer, then either:
or
If you have several layers, then you can use an index (the top layer is
layers[0]
, the bottom/background layer islayers[-1]
), or you figure out the layer by other means, for instance be something like:PS: Your script is likely going to run faster and use less RAM if you freeze the undo stack (or possibly even disable undo entirely) instead of doing undo-groups.