2014年6月13日金曜日

Python-Fuで切り抜きスクリプトを作ってみた。

参考ページ
#!/usr/bin/env python


# Crop images in GIMP Python

from gimpfu import *

def crop(testfp):
    pngimg = pdb.file_png_load(testfp, testfp)
    pngimg.crop(100, 100, 0, 50) # Xが0、Yが50からX,Yともに100ずつ切り抜く
    pdb.file_png_save_defaults(pngimg, pngimg.active_drawable, testfp, testfp)

register(
    "python-fu-crop-sample",
    "Crop an image",
    "Crops the image.",
    "programmm",
    "programmm",
    "2014",
    "test crop",
    "*",
    [
        (PF_STRING, "string","Image file path", None)
    ],
    [],
    crop,
    menu="<Image>/Filters")

main()

Ubuntu 14.04 でPython-Fuを使う。

参考ページ1
参考ページ2

サンプルをインストールしてみる。 Writing GIMP Scripts and Plug-Insからhelloworld.pyをダウンロードする。

$ cp ~/Downloads/helloworld.py ~/.gimp-2.8/plug-ins
$ chmod a+x ~/.gimp-2.8/plug-ins/helloworld.py

gimpを起動→フィルター→Python-Fu→Consoleを選択



























Browseをクリック
















適応をクリック




























こんな感じで引数を入れて実行すると文字入りの画像が作られる。