-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoverlay.py
More file actions
executable file
·95 lines (54 loc) · 2.54 KB
/
Copy pathoverlay.py
File metadata and controls
executable file
·95 lines (54 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/python
import os,glob,sys,time
from gimpfu import *
def process(infile):
print ("Processing file %s " % infile)
image=pdb.gimp_file_load(infile,infile)
image.scale(int(image.width*.5),int(image.height*.5))
filename, file_extension = os.path.splitext(infile)
pdb.gimp_file_save(image, image.active_layer, filename + '_small' + file_extension,filename + '_small' + file_extension)
pdb.gimp_image_delete(image)
def add_layer(infile):
print ("Processing file %s " % infile)
image=pdb.gimp_file_load(infile,infile)
height = pdb.gimp_image_height(image)
width = pdb.gimp_image_width(image)
layer1 = pdb.gimp_layer_new(image,width,height,RGBA_IMAGE,"Overlay",40,NORMAL_MODE) #NORMAL_MODE
pdb.gimp_context_set_background((96,96,96))
pdb.gimp_drawable_fill(layer1, BACKGROUND_FILL)
image.add_layer(layer1,0)
image.flatten()
filename, file_extension = os.path.splitext(infile)
pdb.gimp_file_save(image, image.active_layer, filename + '_overlay' + file_extension, filename + '_overlay' + file_extension)
pdb.gimp_image_delete(image)
def run(directory, process):
start=time.time()
print ("Running on directory \"%s\"" % directory)
if process == 'test':
file_Extentsions = ['*.jpg','*.png']
listoffiles = []
for extension in file_Extentsions:
listoffiles.extend(glob.glob(os.path.join(directory, extension)))
for file in listoffiles:
print(file)
if process == 'overlay':
file_Extensions = ['*.jpg','*.png']
listoffiles = []
for extension in file_Extensions:
listoffiles.extend(glob.glob(os.path.join(directory, extension)))
for file in listoffiles:
print(file)
add_layer(file)
#for infile in glob.glob(os.path.join(directory, '*.jpg')):
# add_layer(infile)
elif process == 'smaller':
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)
run(sys.argv[1], sys.argv[2])
## This file can be run from the command line using the below string
##
# gimp-2.8 -idf --batch-interpreter python-fu-eval -b "import sys;sys.path=['.']+sys.path;import overlay;overlay.run('./images','overlay')" -b "pdb.gimp_quit(1)"