[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.
yield
statement because that question had a requirement for manual intervention in each image. If all you want to do in the image is automated, you can drop theyield
line, as well as the calls topdb.gimp_display_new
andpdb.gimp_display_delete
- and GIMP will process all your images as fast as possible. – jsbueno Jul 28 '17 at 0:53pdb.gimp_file_save(img, img.layers[0],dest_folder + filename,dest_folder + filename)
. Output is RuntimeError: Could not open '/home/pecesaquadros/Desktop/T2//home/pecesaquadros/Desktop/Tââ2/P1050289.JPG' for reading: No such file or directory. I have fiddled around with it. For instance,pdb.gimp_file_save(img, img.layers[0],filename,dest_folder + filename)
andpdb.gimp_file_save(img, img.layers[0],filename,filename)
both let the program run but files are overwritten and not saved in dest_folder. – Á. F. López de Quadros Jul 29 '17 at 10:49