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
|
#!/usr/bin/python
from datetime import date
from gimpfu import *
def watermarkfu(timg, tdrawable,
watermark,
anotherline="<today>",
scalefactor_text=12.0,
scalefactor_boundry=2.3,
watermark_opacity=16.66):
# make copy of input
img = pdb.gimp_image_duplicate(timg)
# simplify source image
img.flatten()
# expand text macro
anotherline = anotherline.replace("<today>",
date.today().strftime("%Y-%m-%d"))
# create text
text = pdb.gimp_text_layer_new(img,
"\n".join([watermark, anotherline]),
"Iosevka Ultra-Bold",
68, UNIT_POINT)
# add to image, justification doesn't work otherwise
img.add_layer(text, 0)
# justify text
pdb.gimp_text_layer_set_justification(img.layers[0], TEXT_JUSTIFY_CENTER)
# scale down text layer, maintaining ratio
pdb.gimp_layer_scale(img.layers[0],
((float(text.width)/text.height)*(img.height/scalefactor_text)),
(img.height/scalefactor_text),
TRUE)
# crate padding around text
pdb.gimp_layer_resize(img.layers[0],
(text.width*scalefactor_boundry),
(text.height*scalefactor_boundry),
(((text.width*scalefactor_boundry)-text.width)/2),
(((text.height*scalefactor_boundry)-text.height)/2),
)
pdb.plug_in_make_seamless(img, img.layers[0])
pdb.plug_in_tile(img, img.layers[0], img.width, img.height, False)
# move to 0,0
(offx, offy) = pdb.gimp_drawable_offsets(img.layers[0])
pdb.gimp_layer_translate(img.layers[0], (offx*-1), (offy*-1))
# tune mode + opacity
pdb.gimp_layer_set_opacity(img.layers[0], watermark_opacity)
pdb.gimp_layer_set_mode(img.layers[0], HARDLIGHT_MODE)
# show to user
pdb.gimp_display_new(img)
register(
"python_fu_watermark",
"WatermarkFu",
"WatermarkFu",
"robertgzr",
"robertgzr",
"2023",
"<Image>/Filters/Render/WatermarkFu",
"RGB*, GRAY*",
[
(PF_STRING, "watermark", "watermark text", ""),
(PF_STRING, "anotherline", "another line", "<today>"),
(PF_FLOAT, "scalefactor_text", "scalefactor text", 12.0),
(PF_FLOAT, "scalefactor_boundry", "scalefactor boundry", 2.3),
(PF_FLOAT, "watermark_opacity", "watermark opacity", 16.66),
],
[],
watermarkfu,
)
main()
|