3

私は python-fu の初心者 (私の 2 日目) なので、私の質問は素朴に思えるかもしれません: 「r400r.png」から長方形の部分を選択し、90 度回転させて、選択内容を「 r400ra.png".

これまでのところ、次の行で何かを試しました。

for fv in range(400,401):
  fn='r%sr.png' % fv
  img=pdb.gimp_file_load('/path/'+fn,fn)
  drw=pdb.gimp_image_get_active_layer(img)
  img1=pdb.gimp_image_new(1024,1568,0)
  lyr=pdb.gimp_layer_new(img1,1024,1568,0,'ly1',0,0)

  pdb.gimp_rect_select(img,10,200,1422,1024,2,0,0)
  drw=pdb.gimp_rotate(drw,0,1.570796327)
  pdb.script_fu_selection_to_image(img1,drw)
  f0=fn[:5]+'a'+fn[5:]
  pdb.gimp_file_save(drw,'/path/'+f0,f0)

「lyr」レイヤーが存在するのは、それが必須であると理解しているためですが、その理由は明らかではありません。「for」ループは最終的に一連のファイルを一括処理する必要があります。テスト用に、1 つのファイルのみに制限されています。「script_fu_selection_to_image」を実行しようとするとエラーが発生します。

正しい方向に向けてください。

ありがとう、SxN

4

1 に答える 1

5

それを行うための PDB 呼び出しは、次の順序で優れています。

# import your image:
img=pdb.gimp_file_load('/path/'+fn,fn)

#make the selection
pdb.gimp_rect_select(img,10,200,1422,1024,2,0,0)


# copy
pdb.gimp_edit_copy(img.layers[0])
# (no need to "get_active_layer" - if
# your image is a flat PNG or JPG, it only has one layer,
# which is accessible as img.layers[0]) 

# create a new image from the copied area:
new_img = pdb.gimp_paste_as_new()

#rotate the newly created image:
pdb.gimp_image_rotate(new_img, ...)

#export the resulting image:
pdb.gimp_file_save(new_img, ...)

#delete the loaded image and the created image:
# (as the objects being destroyed on the Python side
# do not erase then from the GIMP app, where they
# stay consuming memory)
pdb.gimp_image_delete(new_img)
pdb.gimp_image_delete(img)
于 2013-12-26T16:24:04.807 に答える