简体   繁体   English

如何在GIMP脚本中从两个方面缩小选择范围?

[英]How to shrink selection from two sides in GIMP script?

I need to shrink selection in my GIMP script. 我需要在GIMP脚本中缩小选择范围。

Default shrink selection command shrinks the whole selection by given size value in pixels. 默认的缩小选择命令将整个选择缩小指定的像素大小值。

(gimp-selection-shrink inImage 2)

This would shrink selection by 2 pixels. 这会将选择缩小2个像素。

But I don't want to shrink the whole selection. 但我不想缩小整个选择范围。 I just want to remove selection from left and right side, keeping vertical selection unmodified. 我只想从左侧和右侧删除选择,保持垂直选择不变。

That requires removing the farthest pixels on each side (left and right) from selection mask. 这就需要从选择蒙版中删除每侧(左侧和右侧)最远的像素。

How can I do that? 我怎样才能做到这一点?


Script desired effect for value "3px": 脚本对值“ 3px”的预期效果:

https://media.giphy.com/media/l3q2v50vsk8Ze8Ldu/source.gif https://media.giphy.com/media/l3q2v50vsk8Ze8Ldu/source.gif

As you can see, it's quite rectangular on left and right side and it's required for user to make a selection like this. 如您所见,它的左右两侧都相当矩形,用户需要像这样进行选择。

So I think a good approach would be to get left and right posX of selection mask and cut the rect with height of the layer and width of pixels we want to cut off on each side of selection mask. 因此,我认为一种好的方法是获取选择蒙版的左右posX并使用我们要在选择蒙版的每一侧上切掉的图层的高度和像素宽度切割rect。

I'd like to use Script-Fu instead of Python-Fu, because I don't like have extra requirements for the users. 我想使用Script-Fu而不是Python-Fu,因为我不希望对用户有额外的要求。

  • Save your selection 保存选择
  • Get the bounding box ( gimp-selection-bounds ) 获取边界框( gimp-selection-bounds
  • Shrink that box (+2px to Xmin, -4px to width) 缩小框(+ 2px到Xmin,-4px到宽度)
  • Create a rectangle selection from these new values 从这些新值创建矩形选择
  • Intersect with saved selection 与保存的选择相交

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM