codekasten/python-gimp/batch_converter.py

75 lines
2 KiB
Python
Raw Normal View History

#!/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",
"<Toolbox>/Batch mode...", "",
[ (gimpfu.PF_FILE, "listfile", "Listendatei", "") ],
[],
read_filelist)
gimpfu.main()