06-06-2023, 07:04 AM
(06-06-2023, 04:40 AM)y2keeth Wrote:saved as batch.pyCode:
#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
import os, glob, sys, time
from gimpfu import *
def process(infile):
print "Processing file %s " % infile
image = pdb.gimp_file_load(infile, infile, run_mode=RUN_NONINTERACTIVE)
drawable = image.active_layer
print "File %s loaded OK" % infile
pdb.plug_in_photocopy(image, drawable,8.,0.8,0.2,0.2)
outfile=os.path.join('processed',os.path.basename(infile))
outfile=os.path.join(os.path.dirname(infile),outfile)
print "Saving to %s" % outfile
pdb.file_dds_save(image, drawable, outfile, outfile, 7, 0, 0, 0, 0, 7, 0, True,True,2.24,True,False,.5)
print "Saved to %s" % outfile
pdb.gimp_image_delete(image)
def run(directory):
start=time.time()
print "Running on directory \"%s\"" % directory
# os.mkdir(os.path.join(directory,'processed'))
for infile in glob.glob(os.path.join(directory, '*.jpg')):
process(infile)
end=time.time()
print "Finished, total processing time: %.2f seconds" % (end-start)
if __name__ == "__main__":
print "Running as __main__ with args: %s" % sys.argv
not sure where the directory is in this code?
It is not, since it is specified in the shell command that launches gimp (the './images' string, that you can replace by any directory spec).
Code:
gimp -idf --batch-interpreter python-fu-eval -b "import sys;sys.path=['.']+sys.path;import batch;batch.run('./images')" -b "pdb.gimp_quit(1)"
If you are on Windows, note that for Python backslashes in strings have a special meaning so have to be doubled if they keep their plain character status, but you can uses plain slashes instead, so it's either 'C:\\Path\\to\\some\\directory' or 'C:/Path/to/some/directory'(*)
(*) For completeness tattooed python users can also use the form r'C:\Path\to\some\directory' but they know better