2013-12-12 25 views
2

我是python-fu的新手,(我的第二天),所以我的問題看起來很天真:我想從「r400r.png」中選擇一個矩形部分,旋轉它90度,並將我的選擇保存在「r400ra.png」中。python-fu select copy paste

到目前爲止,我試圖在這些線路上的東西:

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」循環最終應該批量處理一堆文件;測試它僅限於一個文件。我嘗試執行「script_fu_selection_to_image」時出現錯誤。

請問您能否指點我正確的方向?

感謝, SxN

回答

2

的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) 
+0

這個問題是兩歲,但使用'瘸子v2.8.10'在Ubuntu ... ,'pdb.gimp_paste_as_new()'會觸發'error:procedure not found' – SebasSBM

+2

在gimp v2.8.10中,這個函數現在被稱爲'pdb.gimp_edit_paste_as_new()' – SebasSBM