diff options
| author | Robert Günzler <r@gnzler.io> | 2023-11-02 06:38:43 +0100 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2023-11-02 06:38:43 +0100 |
| commit | de2930126ed9cfcf0b3c6ca1a405bef501f897b7 (patch) | |
| tree | df275b35d7b3e2f455dde123b42887ff16f1d4d3 /.local/share | |
| parent | 3b1944338705063768552313660ca66823ab07f4 (diff) | |
add watermark plugin for gimp
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to '.local/share')
| -rwxr-xr-x | .local/share/GIMP/plug-ins/watermark.py | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/.local/share/GIMP/plug-ins/watermark.py b/.local/share/GIMP/plug-ins/watermark.py new file mode 100755 index 0000000..0f9f1f9 --- /dev/null +++ b/.local/share/GIMP/plug-ins/watermark.py @@ -0,0 +1,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() |