Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
gimp native batch convert?
#11
(05-27-2023, 07:57 AM)Ofnuts Wrote: Filters ➤ Python-fu ➤ Console  ➤ Browse and ennter DDS in the search bar:



And if you hit Apply the python console is pre-filled with a call:



So, possibly, using the same names as in the python example code:

Code:
pdb.file_dds_save(image, drawable, outfile, outfile, 7, 0, 0, 0, 0, 7, 0, True,True,2.24,True,False,.5)

Where the 7 is the documented value for RXGB (DXT5).

The python documentation should be read with a grain of salt because it is auto-generated from the same sources as the script-fu docs and Pythin and Scheme have a different syntax.
  • Dashes in variable/constant names should be replaced by underscores
  • When present, the run-mode first argument should be ignored, it is not used in Python (it is actually optional, and specified differently)
  • Toggles that are specified as INT32 can be entered as boolean (False: 0, True: 1, and mind the initial capital). This is a bit more readable.
  • Many calls define constants names for their arguments when necessary, better use them when they exists (alas, not for the DDS plugin, it they had existed you could have used DDS_FORMAT_RXGB_DXT5 and DDS_MIPMAPS_NONE that are a bit less mysterious than 7 and 0)
  • For long calls, you can also enter the call like this, to put a comment with each argument, only the first line needs to be correctly indented:
Code:
pdb.file_dds_save(image, drawable, outfile, outfile,
                    7,      # DDS type
                    0,      # no mipmaps
                    0,      # save layer
                    0,      # Default pixel format
                    0,      # Transparent color is First
                    7,      # Lanczos filtering
                    0,      # Default wrap mode
                    True,   # gamma-correct filtering
                    True,   # Use sRGB
                    2.24,   # Gamma value
                    True,   # Perceptual compression
                    False,  # Preserve alpha
                    .5,     # Alpha (ignored, due to previous)
                    )        

ok thanks I will try that
Reply
#12
#!/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?
Reply
#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
#14
(06-06-2023, 07:04 AM)Ofnuts Wrote:
(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

ok thanks I think i get it now, I hope
Reply
#15
got a error here is the console

GIMP 2.10.34 Python Console
Python 2.7.18 (default, Jan 14 2023, 22:21:24)  [GCC 12.2.0 64 bit (AMD64)]
➤> gimp -idf --batch-interpreter python-fu-eval -b "import sys;sys.path=['.']+sys.path;import batch;batch.run('e:/test')" -b "pdb.gimp_quit(1)"
 File "<input>", line 1
   gimp -idf --batch-interpreter python-fu-eval -b "import sys;sys.path=['.']+sys.path;import batch;batch.run('e:/test')" -b "pdb.gimp_quit(1)"
                                      ^
SyntaxError: invalid syntax
➤>
Reply
#16
This line isn't meant for the Python console. It is used to invoke Gimp from a command prompt (CMD.EXE, DOS shell, "black screen", etc...)

Running everything in the Python console is possible too. Copy-paste the definition of the run() and process() methods in the Python console, and then call run('/path/to/directory') in that same Python console.
Reply
#17
(06-08-2023, 08:29 AM)Ofnuts Wrote: This line isn't meant for the Python console. It is used to invoke Gimp from a command prompt (CMD.EXE, DOS shell, "black screen", etc...)

Running everything in the Python console is possible too. Copy-paste the definition of the run() and process() methods in the Python console, and then call run('/path/to/directory') in that same Python console.

how do i access the command prompt?
Reply
#18
(06-09-2023, 04:53 AM)y2keeth Wrote:
(06-08-2023, 08:29 AM)Ofnuts Wrote: This line isn't meant for the Python console. It is used to invoke Gimp from a command prompt (CMD.EXE, DOS shell, "black screen", etc...)

Running everything in the Python console is possible too. Copy-paste the definition of the run() and process() methods in the Python console, and then call run('/path/to/directory') in that same Python console.

how do i access the command prompt?

Several ways. But frankly, if you have to ask this... it's a bit as if you asked for instructions to fix your car transmission, and you don't know how to open the hood...
Reply
#19
(06-09-2023, 08:10 AM)Ofnuts Wrote:
(06-09-2023, 04:53 AM)y2keeth Wrote:
(06-08-2023, 08:29 AM)Ofnuts Wrote: This line isn't meant for the Python console. It is used to invoke Gimp from a command prompt (CMD.EXE, DOS shell, "black screen", etc...)

Running everything in the Python console is possible too. Copy-paste the definition of the run() and process() methods in the Python console, and then call run('/path/to/directory') in that same Python console.

how do i access the command prompt?

Several ways. But frankly, if you have to ask this... it's a bit as if you asked for instructions to fix your car transmission, and you don't know how to open the hood...

sorry i thought the   python console was the command prompt, so i dont know how to open the hood lol. still new to gimp coming from photoshop

found it nevermind

now i get this error

PS C:\Users\bheadr> gimp -idf --batch-interpreter python-fu-eval -b "import sys;sys.path=['.']+sys.path;import batch;batch.run('e:/test')" -b "pdb.gimp_quit(1)"
gimp : The term 'gimp' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ gimp -idf --batch-interpreter python-fu-eval -b "import sys;sys.path= ...
+ ~~~~
+ CategoryInfo : ObjectNotFound: (gimp:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Reply
#20
Now you are in Windows territory...  you have two problems:

  1. You appear to be running the "PowerShell" and not the classic (aka "DOS" shell). Maybe the PS is compatible enough, but the command is crafted to navigate the intricacies of the quoting syntax in both the shell and the Python language, so it the shell syntax is bit different this could break things.
  2. In either shell, when you issue a command (gimp in this case) it searches a gimp.exe in a set of known directories. But these are known to the system because they have been added to the PATH environment variable. An alternative is to specify the full path to the executable (which is fraught with peril since MS had the great idea to use a name with spaces in it, so you have to add more quotes).
This is about as far as I can get for you. To go further I'll have to make screenshots, which means installing Windows somewhere... and nope.
Reply


Forum Jump: