Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
gimp native batch convert?
#13
(06-06-2023, 04:40 AM)y2keeth Wrote:
Code:
#!/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
saved as batch.py

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 Smile
Reply


Messages In This Thread
gimp native batch convert? - by y2keeth - 05-22-2023, 12:39 AM
RE: gimp native batch convert? - by Ofnuts - 05-22-2023, 07:28 AM
RE: gimp native batch convert? - by y2keeth - 05-22-2023, 08:51 AM
RE: gimp native batch convert? - by y2keeth - 05-23-2023, 03:28 AM
RE: gimp native batch convert? - by Ofnuts - 05-23-2023, 12:38 PM
RE: gimp native batch convert? - by y2keeth - 05-24-2023, 04:55 AM
RE: gimp native batch convert? - by y2keeth - 05-26-2023, 01:21 AM
RE: gimp native batch convert? - by y2keeth - 05-27-2023, 05:21 AM
RE: gimp native batch convert? - by rich2005 - 05-27-2023, 07:25 AM
RE: gimp native batch convert? - by Ofnuts - 05-27-2023, 07:57 AM
RE: gimp native batch convert? - by y2keeth - 05-28-2023, 01:47 AM
RE: gimp native batch convert? - by y2keeth - 06-06-2023, 04:40 AM
RE: gimp native batch convert? - by Ofnuts - 06-06-2023, 07:04 AM
RE: gimp native batch convert? - by y2keeth - 06-07-2023, 03:06 AM
RE: gimp native batch convert? - by y2keeth - 06-08-2023, 04:19 AM
RE: gimp native batch convert? - by Ofnuts - 06-08-2023, 08:29 AM
RE: gimp native batch convert? - by y2keeth - 06-09-2023, 04:53 AM
RE: gimp native batch convert? - by Ofnuts - 06-09-2023, 08:10 AM
RE: gimp native batch convert? - by y2keeth - 06-10-2023, 03:46 AM
RE: gimp native batch convert? - by Ofnuts - 06-10-2023, 06:44 AM
RE: gimp native batch convert? - by y2keeth - 06-13-2023, 03:53 AM
RE: gimp native batch convert? - by y2keeth - 06-19-2023, 11:44 AM

Forum Jump: