From f20773d915d8c44603ce6246014133701c262877 Mon Sep 17 00:00:00 2001 From: lars Date: Tue, 13 Oct 2009 03:14:24 +0000 Subject: [PATCH] added an example gimp-python plugin for applying some filters to a list of files (non-interactively) --- python-gimp/batch_converter.py | 74 ++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 python-gimp/batch_converter.py diff --git a/python-gimp/batch_converter.py b/python-gimp/batch_converter.py new file mode 100755 index 0000000..531d7d4 --- /dev/null +++ b/python-gimp/batch_converter.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python +# +# Requisites: +# install vignette plugin: http://blog.tigion.de/2008/07/19/gimp-script-fu-photo-vignette/ +# link this script to ~/.gimp-2.6/plug-ins/ +# +# How to run: +# start gimp +# click (maybe twice) at the "Batch mode" menu entry (next to "Help") +# choose a file, that contains a list of absolute filenames of pictures (one per line) +# +# The resulting pictures are placed besides the originals with the given prefix (default: "converted_"). +# +# Adapt the settings below to your needs! +# + +import gimp +import gimpfu +import sys +import os + +FILE_PREFIX = "converted_" + +# default: 7 +CARTOON_RADIUS = 30 +# default: 0.2 +CARTOON_BLACK = 0.4 +# default: 2 +POSTERIZE_COLORS = 4 +# default: (0, 0, 0) +VIGNETTE_COLOR = (0, 0, 0) +# default: 60 (%) (Deckkraft) +VIGNETTE_COVERAGE = 60 +# default: 5 +VIGNETTE_RADIUS = 5 +# default: 75 (Haerte) +VIGNETTE_STRENGTH = 75 + + +def get_output_filename(infilename): + return os.path.join(os.path.dirname(infilename), FILE_PREFIX + os.path.basename(infilename)) + + +def handle_file(infilename): + #pic = gimp.pdb.file_jpeg_load(infilename, gimpfu.RUN_NONINTERACTIVE) + pic = gimp.pdb.gimp_file_load(infilename, gimpfu.RUN_NONINTERACTIVE) + layer = pic.layers[0] + gimp.pdb.plug_in_cartoon(pic, layer, CARTOON_RADIUS, CARTOON_BLACK) + gimp.pdb.gimp_posterize(layer, POSTERIZE_COLORS) + gimp.pdb.script_fu_photo_vignette(pic, layer, + VIGNETTE_COLOR, VIGNETTE_COVERAGE, VIGNETTE_RADIUS, VIGNETTE_STRENGTH) + output_filename = get_output_filename(infilename) + gimp.pdb.gimp_file_save(pic, layer, output_filename, output_filename, run_mode=gimpfu.RUN_NONINTERACTIVE) + + +def read_filelist(listfile): + for line in file(listfile).read().splitlines(): + handle_file(line) + + +gimpfu.register( + "python_fu_batch_convert", + "Convert some pictures via batch mode", + "Convert some pictures via batch mode", + "Lars Kruse", + "Lars Kruse", + "2009", + "/Batch mode...", "", + [ (gimpfu.PF_FILE, "listfile", "Listendatei", "") ], + [], + read_filelist) + +gimpfu.main() +