2016-11-04 51 views
1

我想用python_fu編寫一個gimp插件。我希望它採用大量相同大小的圖層並將它們放在垂直線上。這將用於打開每個頁面佔據一個圖層的pdf文件,並且該插件將它們排成一行。當我運行插件時,菜單中沒有任何內容出現。當我用上面的星號註釋掉該行時,插件會加載到菜單中。Python_fu插件將不會載入瘸子

%USERPROFILE%\。GIMP - 2.8 \插件\ Array.py

from gimpfu import * 

def plugin_main(timg, tdrawable, widthNum, heightNum): 

    layers = gimp-image-get-layers(timg) #<< Gets a list of all the layers 

    #Sets the WIDTH and HEIGHT to the size of the first image 
    WIDTH = layers[0].width 
    HEIGHT = layers[0].height 

    #Loops through all layers and moves them 
    for i in range(layers.length): 
     location = float((i+1)*HEIGHT) 
     #***** 
     transformedimage = gimp-item-transform-2d(layers[i], 0.0, 0.0, 1.0, 1.0, 0.0, location) #<< When I comment this line out the plugin loads 

    gimp-image-resize-to-layers() #<< Resizes the image to fit the moved layers 

register(
     "python_fu_array", 
     "Sets out your layers as tiles", 
     "Sets out your layers as tiles", 
     "author", 
     "author", 
     "2016", 
     "<Image>/Image/Array", 
     "RGB*, GRAY*", 
     [], 
     [], 
     plugin_main) 

main() 

回答

2

看一看一些現有的基於Python的插件,例如https://git.gnome.org/browse/gimp/tree/plug-ins/pygimp/plug-ins/py-slice.py

注意一些怎樣過程被稱爲有,例如,管線168: https://git.gnome.org/browse/gimp/tree/plug-ins/pygimp/plug-ins/py-slice.py#n168

temp_image = pdb.gimp_image_new (...) 

有兩種差異代碼:

  1. 的PDB前綴
  2. 下劃線代替連字符/弊

改變你的插件像這樣做,你會得到進一步的幾個步驟。

+1

UST是完全清楚的:'gimp- Python中的item-transform-2d'將意味着一系列的減法 - 而不是變量名稱。 Python中的GIMP API名稱替換爲'_'的'-'。並且它們在'pdb'命名空間中 - 所以 - 改變你的問題行來包含'pdb.gimp_item_transform-2d(...)'而不是當前的表單。 – jsbueno

0

除了Michael的評論,Python-fu界面defines python-style objects and classes for many Gimp concepts所以你可以經常避免使用pdb。*函數。比如迭代的圖像層:

您的代碼: 層= GIMP圖像,得到層(TIMG)#< <獲取所有層的列表

#Sets the WIDTH and HEIGHT to the size of the first image 
WIDTH = layers[0].width 
HEIGHT = layers[0].height 

#Loops through all layers and moves them 
for i in range(layers.length): 

更好的代碼:

# better use the image height/width, layer h/w can be different 
width=image.width 
height=image.height 

for position,layer in enumerate(image.layers): 
    # etc.... 

我們都做錯誤。通過在命令提示符下調用腳本中的Python,即使不啓動Gimp,也可以清除最大的語法錯誤。如果只是抱怨gimpfu,你將很有可能會在Gimp下運行。

  • 對於初學者良好的Python建議:www.python-forum.io
  • 對於初學者良好的Python瘸子建議:www.gimp-forum.net
+0

只是另一種說法 - 這種交互圖層的方式不再好,因爲它不考慮圖層組。 – jsbueno

+0

我在SE上寫了一些關於如何進入圖層組的帖子。 –

+0

@jsbueno在一般情況下是的,但在許多情況下它可能足夠好。整個腳本看起來像它期望一個特定的層設置。 – xenoid