Mobile app version of vmapp.org
Login or Join
Gretchen549

: GIMP: A code to edit a whole folder of images [GIMP 2.8.16] EDITED: See below. Hi, I am new to python, and I need to ask the community to please help me find where is this code failing.

@Gretchen549

Posted in: #Gimp #ImageEditing #Images #Python #Script

[GIMP 2.8.16]



EDITED: See below.

Hi,

I am new to python, and I need to ask the community to please help me find where is this code failing. I am having trouble. This is version 1.0, following this answer:

import glob
source_folder = "/home/pecesaquadros/Desktop/T/"
dest_folder = "/home/pecesaquadros/Desktop/T2/"

def auto(source_folder, dest_folder):
for filename in glob(source_folder + "/*.JPG"):
img = pdb.gimp_file_load(source_folder + filename, source_folder + filename)
pdb.gimp_image_rotate(img,0)
pdb.gimp_image_convert_grayscale(img)
drawable = pdb.gimp_image_get_active_drawable(img)
pdb.gimp_brightness_contrast(drawable, 28,100)
disp = pdb.gimp_display_new(img)
yield img
pdb.gimp_image_merge_visible_layers(img, CLIP_TO_IMAGE)
pdb.gimp_file_save(img, img.layers[0], dest_folder + filename, dest_folder + filename)
pdb.gimp_display_delete(disp)
pdb.gimp_image_delete(img) # drops the image from gimp memory

seq = auto(source_folder, dest_folder)
next(seq)


with output, in GIMP 2.8.16 Python Console:

Traceback (most recent call last):
File "<input>", line 1, in <module>
File "<input>", line 2, in auto
TypeError: 'module' object is not callable


Many thanks. I am sure this question will help many. I might make a plugin out of it, with interesting parameters, available for everybody; it will be named "Photocopy" :)

...next I am creating a loop to create a TeX code that will compile all images to a pdf...

Thanks again,

Al



EDIT

New code:

import glob
source_folder = "/home/pecesaquadros/Desktop/T/"
dest_folder = "/home/pecesaquadros/Desktop/T2/"

def auto(source_folder, dest_folder):
for filename in glob.glob(source_folder + "/*.JPG"): #blabla .JPG
img = pdb.gimp_file_load(filename,filename)
pdb.gimp_image_rotate(img,0) #Editing starts
pdb.gimp_image_convert_grayscale(img)
pdb.gimp_image_select_rectangle(img, 2, 0, 0, 1839, 600)
drawable = pdb.gimp_image_get_active_drawable(img)
pdb.gimp_brightness_contrast(drawable, 60,127)
pdb.gimp_image_select_rectangle(img, 2, 0, 600, 1839, 900)
drawable = pdb.gimp_image_get_active_drawable(img)
pdb.gimp_brightness_contrast(drawable, 32,127)
pdb.gimp_image_select_rectangle(img, 2, 0, 1500, 1839, 900)
drawable = pdb.gimp_image_get_active_drawable(img)
pdb.gimp_brightness_contrast(drawable, 14,127)
pdb.gimp_image_select_rectangle(img, 2, 0, 2400, 1839, 900)
drawable = pdb.gimp_image_get_active_drawable(img)
pdb.gimp_brightness_contrast(drawable, 0,127)
disp = pdb.gimp_display_new(img) #Editing ends
yield img #Image is displayed for me to manipulate
pdb.gimp_image_merge_visible_layers(img, CLIP_TO_IMAGE)
pdb.gimp_file_save(img, img.layers[0],filename,dest_folder + filename)
pdb.gimp_display_delete(disp)
pdb.gimp_image_delete(img)

seq = auto(source_folder, dest_folder)
next(seq) #This, and enter, to go to the next file


Results in:


Files are overwritten, not saved in the new folder
Sometimes, and only sometimes, one of these two errors appear:


A



B



0_0

PS: yield is in my plans.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Gretchen549

1 Comments

Sorted by latest first Latest Oldest Best

 

@Steve758

glob is module that contains a glob function, so that shouldn't be glob(source_folder + "/*.JPG") but glob.glob(source_folder + "/*.JPG")

Also, if you give a path as part of the pattern to glob.glob(), the output will contain the full path to the files. Since you are re-adding the directory name to it, it appears twice in the name you give to gimp_file_load(). So try something like:

for filename in glob.glob(source_folder + "/*.JPG"):
img = pdb.gimp_file_load(filename,filename)

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme