Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Newbie: Python script error
#1
Question 
I am very new to the Python scripting in Gimp. I have used Gimp in the past for manipulating individual images, but now I have to run specific operations on hundreds of images. So I checked into the scripting options. I discarded Script-fu, as I am familiar with programming languages like C, C++, etc., but the Schemes thing is quite different. Python, on the other hand is similar enough.

So, to start out I looked at some sample scripts like this one:

Code:
import glob
source_folder = "c:/mysource_image_folder/" #type your folder inside the quotes - append the final "/"
dest_folder = "c:/destination_folder/"
for filename in glob.glob(source_folder  + "/*.png"):
   img = pdb.gimp_file_load(source_folder + filename, source_folder + filename)
   pdb.gimp_drawable_brightness_contrast(img.layers[0], 0.2, 0)
   pdb.gimp_file_save(img, img.layers[0], dest_folder + filename, dest_folder + filename)
   pdb.gimp_image_delete(img)  # drops the image from gimp memory

When I copy and paste that into the Python window, I get an error right away on the "import glob" line (I also get that error when I just type in "import glob"):

import glob
  File "<input>", line 1
    rt glob
          ^
SyntaxError: invalid syntax

So, obviously I am doing something wrong. Did I not install something right? I installed Python 3.7 (Win10), then reinstalled Gimp 2.10.20. Do I need to do something else?

And apologies if this is the wrong thread. Please point me to the right thread if so.

Thanks.
Reply


Messages In This Thread
Newbie: Python script error - by mike_b - 10-07-2020, 05:27 PM
RE: Newbie: Python script error - by Ofnuts - 10-07-2020, 08:05 PM

Forum Jump: