Skip to content

Instantly share code, notes, and snippets.

@netguy204
Created January 2, 2010 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netguy204/267538 to your computer and use it in GitHub Desktop.
Save netguy204/267538 to your computer and use it in GitHub Desktop.
; batch watermarking tool written in script-fu for the gimp
; Copyright 2010 Brian Taylor
; el.wubo@gmail.com
;
; Redistribute under the terms of the GNU General Public License version 2 or better
(define (add-text org-img new-layer msg-x msg-y the-text the-size the-font)
(let* ((floating-layer (car (gimp-text-fontname org-img new-layer msg-x msg-y the-text 1 TRUE the-size 0 the-font))))
(gimp-floating-sel-anchor floating-layer)))
(define (script-fu-batch-watermark the-dir the-color the-text the-font the-size-perc offset)
(let* ((the-glob (string-append the-dir "/*"))
(filelist (cadr (file-glob the-glob 1))))
(while (not (null? filelist))
(let* ((filename (car filelist))
(image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
(drawable (car (gimp-image-get-active-layer image))))
(script-fu-watermark image drawable the-color the-text the-font the-size-perc offset)
(gimp-image-flatten image)
(let* ((drawable (car (gimp-image-get-active-layer image))))
(gimp-file-save RUN-NONINTERACTIVE image drawable filename filename))
(gimp-image-delete image))
(set! filelist (cdr filelist)))))
(define (script-fu-watermark org-img org-layer the-color the-text the-font the-size-perc offset)
(let* ((pic-layer (car (gimp-image-get-active-drawable org-img)))
(img-width (car (gimp-drawable-width pic-layer)))
(img-height (car (gimp-drawable-height pic-layer)))
(the-size (min (* .01 the-size-perc img-height) (* .01 the-size-perc img-width)))
(msg-extents (gimp-text-get-extents-fontname the-text the-size 1 the-font))
(msg-width (car msg-extents))
(msg-height (car (cdr msg-extents)))
(msg-x (- img-width msg-width))
(msg-y (- img-height msg-height))
(new-layer (car (gimp-layer-new org-img img-width img-height RGBA-IMAGE "watermark" 100 NORMAL-MODE))))
(gimp-context-push)
(gimp-image-undo-group-start org-img)
(gimp-image-add-layer org-img new-layer -1)
(gimp-context-set-foreground "white")
(add-text org-img new-layer (- msg-x offset) (+ msg-y offset) the-text the-size the-font)
(gimp-context-set-foreground the-color)
(add-text org-img new-layer msg-x msg-y the-text the-size the-font)
(gimp-image-undo-group-end org-img)
(gimp-displays-flush)
(gimp-context-pop)))
(script-fu-register "script-fu-watermark"
_"Watermark image..."
_"Add a watermark to an image"
"Brian Taylor el.wubo@gmail.com"
"Brian Taylor"
"Jan 2010"
"RGB*, INDEXED*, GRAY*"
SF-IMAGE "Image" 0
SF-DRAWABLE "Layer" 0
SF-COLOR "Text color" "black"
SF-STRING "Text" "Copyright 2010 Someone"
SF-FONT "Font" "Sans"
SF-ADJUSTMENT "Size (percent)" '(3 1 10 1 10 0 1)
SF-ADJUSTMENT "Offset (pixels)" '(3 1 10 1 10 0 1))
(script-fu-menu-register "script-fu-watermark"
"<Image>/Image")
(script-fu-register "script-fu-batch-watermark"
_"Watermark images..."
_"Add a watermark to a directory full of images"
"Brian Taylor el.wubo@gmail.com"
"Brian Taylor"
"Jan 2010"
""
SF-DIRNAME "Directory" "/"
SF-COLOR "Text color" "black"
SF-STRING "Text" "Copyright 2010 Someone"
SF-FONT "Font" "Sans"
SF-ADJUSTMENT "Size (percent)" '(3 1 10 1 10 0 1)
SF-ADJUSTMENT "Offset (pixels)" '(3 1 10 1 10 0 1))
(script-fu-menu-register "script-fu-batch-watermark"
"<Image>/Image/Batch")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment