2017-03-19 1 views
0

Select -> To Pathを使用していくつかのパスでGIMP 2.8でイメージを作成しました。今度は、これらすべてのパスをループするPythonスクリプトを作成し、各パスに基づいて選択し、選択したものを新しい画像に切り取り、追加のものを追加します。 と切り捨てて別のPNG画像に保存します。GIMP Python、メニュー項目 "パスから"と同じではないパスに基づく選択

これまでのところ、私はメニュー項目としてFilters -> Pathsから開始することができ、このPythonスクリプトを、持っている:

#!/usr/bin/env python 
# coding: utf-8 

from gimpfu import * 
import os 

def export_paths_to_pngs(img, layer, path, vis): 

    # get all paths (internally called "vectors") 
    cnt, vectors = pdb.gimp_image_get_vectors(img) 
    if (cnt > 0): 
     # iterate all paths 
     for n in vectors: 
      v = gimp.Vectors.from_id(n) 
      # only visible paths 
      if (v.visible): 
       st = v.strokes 
       sufix = 0 
       # iterate all strokes in vector 
       for ss in st: 
        type, num_pnts, cntrlpnts, closed = pdb.gimp_vectors_stroke_get_points(v, ss.ID) 
        pdb.gimp_image_select_polygon(img, CHANNEL_OP_REPLACE, len(cntrlpnts), cntrlpnts) 

# tell gimp about our plugin 
register(
    "python_fu_export_paths_to_png", 
    "Export paths as png files", 
    "Export paths as png files", 
    "BdR", 
    "BdR", 
    "2017", 
    "<Image>/Filters/Paths/Export paths to png", # menu path 
    "", # Create a new image, don't work on an existing one 
    [ 
     (PF_DIRNAME, "export_directory", "Export destination directory", "/tmp"), 
     (PF_TOGGLE, "p2", "TOGGLE:", 1)  
    ], 
    [], 
    export_paths_to_pngs 
) 

main() 

しかし、問題は、意図したとおりのpython機能gimp_image_select_polygonが選択をしていないということです。 選択にはベジェ曲線(またはそのようなもの)にいくつかの違いがあるようですが、それはそれが基づいているパスとまったく同じではありません。 一方、メニュー項目From Pathは正しく動作し、パスに基づいて完全な選択を行います。だから私の質問はあり

enter image description here

:下の画像を参照してください

  1. 私が間違って機能gimp_image_select_polygonを使用しています
  2. gimp_image_select_polygonメニュー項目 Select -> From PathとGimpPython機能の違いは何ですか、または私は使用すべき別の機能がありますか?
  3. それでも問題が解決しない場合は、何とかメニュー項目From PathをPythonから直接呼び出す方法がありますか?

答えて

1

(「ポリゴン」モードでのフリーハンドの選択など)、多角形選択を作成するためのものです

pdb.gimp_image_select_polygon(...) 

を使用しないでください。

pdb.gimp_image_select_item(image,CHANNEL_OP_REPLACE,path) 

(パス全体で、ストロークでストロークする必要はありません)。

PS:パス上で反復するコードは非常に工夫されています。

for v in img.vectors: 
    if v.visible: 
+0

おかげ 'pdb.gimp_image_select_item'は私が探していたまさにです:それは通常と同じくらい簡単です。また、単純化された 'for'ループを指摘してくれてありがとう。 – BdR

関連する問題