Bye Bye Moore

PoCソルジャーな零細事業主が作業メモを残すブログ

python-fuで画像を弄る その1:とりあえず使ってみる

実際のところ

Gimpを開いて「フィルター」 =>「 Python-fu」

手元環境では何故かPython2.7系と古い上に、メソッド中で空白を入れるとインデント不正で怒られる……。

試す

外付けストレージ"D"の特定パターンの画像に赤い丸を

from gimpfu import *
import glob

def draw_red_circle(image_path, x, y, radius):
    # Open the image
    image = pdb.gimp_file_load(image_path, image_path)
    # Get the layer of the opened image
    layer = pdb.gimp_image_get_active_layer(image)
    # Set foreground color to red
    pdb.gimp_context_set_foreground((255, 0, 0))
    # Draw the circle
    pdb.gimp_ellipse_select(image, x, y, radius, radius, CHANNEL_OP_REPLACE, True, False, 0)
    pdb.gimp_edit_bucket_fill(layer, BUCKET_FILL_FG, LAYER_MODE_NORMAL, 100, 0, False, 0, 0)
    pdb.gimp_selection_none(image)
    # Save the image
    pdb.gimp_file_save(image, layer, image_path, image_path)
    pdb.gimp_image_delete(image)

# Get a list of all image files
image_files = glob.glob(u"D:/*_b.png")

# Call the function for each image
for image_file in image_files:
    draw_red_circle(image_file, x=100, y=100, radius=50)