;;; Copyright © 2005 Jeremy English ;;; ;;; Permission to use, copy, modify, distribute, and sell this software and its ;;; documentation for any purpose is hereby granted without fee, provided that ;;; the above copyright notice appear in all copies and that both that ;;; copyright notice and this permission notice appear in supporting ;;; documentation. No representations are made about the suitability of this ;;; software for any purpose. It is provided "as is" without express or ;;; implied warranty. ;;; ;;; Created: 12-December-2005 (define alpha '("A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z" ) ) (define (rand-char) (nth (fmod (rand) 52) alpha)) (define (rand-range n) (fmod (rand) n)) (define (get-rand-size min-font max-font) (let* ((rs (rand-range max-font))) (cond ((< rs min-font) (set! rs min-font))) rs)) (define (get-char use-random char) (cond ((= TRUE use-random) (rand-char)) (t char))) (define (image-fill-text-print-m n-chars image old-drawable new-drawable font max-font min-font use-random char) ;Pick a random position on the image. (let* ((width (car (gimp-drawable-width old-drawable))) (height (car (gimp-drawable-height old-drawable))) (color 0) (rand-x (rand-range width)) (rand-y (rand-range height)) (rand-size (get-rand-size min-font max-font)) (c (get-char use-random char))) (cond ((= n-chars 0) t) (t ;Pull the color from that position on the orignal image (gimp-palette-set-foreground (car (gimp-image-pick-color image old-drawable rand-x rand-y 0 1 min-font))) ;Place a random char with that color on the new layer (gimp-text-fontname image new-drawable rand-x rand-y c 0 TRUE rand-size PIXELS font) ;repeat (image-fill-text-print-m (- n-chars 1) image old-drawable new-drawable font max-font min-font use-random char))))) (define (script-fu-image-fill-text image drawable font max-font min-font n-chars use-random char) (let* ((old-fg (car (gimp-palette-get-foreground))) (text-layer 0)) ; Create new layer and add to the image (set! text-layer (car (gimp-layer-copy drawable 1))) (gimp-image-add-layer image text-layer -1) (gimp-layer-set-name text-layer "text") (gimp-drawable-fill text-layer BG-IMAGE-FILL) (image-fill-text-print-m n-chars image drawable text-layer font max-font min-font use-random char) ; Cleanup (gimp-palette-set-foreground old-fg) (gimp-image-merge-visible-layers image 1) (gimp-displays-flush))) (script-fu-register "script-fu-image-fill-text" _"/Script-Fu/Render/Image Fill Text..." "Fill the image with random characters." "Jeremy English " "Jeremy English" "2005/12/12" "RGB GRAY" SF-IMAGE "Image" 0 SF-DRAWABLE "Drawable" 0 SF-FONT "Font" "Serif" SF-VALUE "Max Font Size" "50" SF-VALUE "Min Font Size" "10" SF-VALUE "Number of Characters" "500" SF-TOGGLE "Use Random Characters" TRUE SF-STRING "Character" "A")