#!/usr/bin/python from datetime import date from gimpfu import * def watermarkfu(timg, tdrawable, watermark, anotherline="", 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("", 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", "/Filters/Render/WatermarkFu", "RGB*, GRAY*", [ (PF_STRING, "watermark", "watermark text", ""), (PF_STRING, "anotherline", "another line", ""), (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()