; Custom Font Rel 1 ; Created by Tin Tran ; Comments directed to http://gimpchat.com or http://gimpscripts.com ; ; License: GPLv3 ; This program is free software: you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation, either version 3 of the License, or ; (at your option) any later version. ; ; This program is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; To view a copy of the GNU General Public License ; visit: http://www.gnu.org/licenses/gpl.html ; ; ; ------------ ;| Change Log | ; ------------ ; Rel 1: Initial release. Changed from words-to-circles script over to words to house script. (define (script-fu-word-to-shape image layer text font center-x center-y radius color draw-circle circle-instead ) (let* ( (width (car (gimp-image-width image))) (height (car (gimp-image-height image))) (text-length 0) (spaces 0) (text-layer 0) (text-width 0) (space-width 0) (bw-layer 0) (current-color 0) (charList 0) (x1 0) (char 0) (char-width 0) (x2 0) (a 0) (b1 0) (b2 0) ) ;(gimp-image-undo-disable image); DN = NO UNDO (gimp-context-push) (gimp-image-undo-group-start image) ;undo-group in one step (set! text-length (string-length text)) (set! spaces (+ text-length 1)) (set! text-layer (car (gimp-text-layer-new image text font 200 0))) (gimp-image-insert-layer image text-layer 0 0) (set! text-width (car (gimp-drawable-width text-layer))) (gimp-image-remove-layer image text-layer) ;remove layer after we have text-width ; must i manually create all letters individually and add them up...don't know but this is the work around for now (set! text-width 0) (set! charList (map (lambda (x) (make-string 1 x)) (string->list text))) ;create the list of letters (while (not (null? charList)) (set! char (car charList)) (set! text-layer (car (gimp-text-layer-new image char font 200 0))) (gimp-image-insert-layer image text-layer 0 0) (set! text-width (+ text-width (car (gimp-drawable-width text-layer)))) (gimp-image-remove-layer image text-layer) ;remove layer after we have text-width (set! charList (cdr charList)) ) ; must i manually ... end (set! space-width (/ (* radius 2) (+ (* text-length 7) 2))) (set! bw-layer (car (gimp-layer-new image width height RGBA-IMAGE text 100 NORMAL-MODE))) (gimp-image-insert-layer image bw-layer 0 0) (if (= draw-circle TRUE) (begin (set! current-color (car (gimp-context-get-foreground))) (gimp-context-set-foreground color) (if (= circle-instead TRUE) (begin (gimp-image-select-ellipse image CHANNEL-OP-REPLACE (- center-x radius) (- center-y radius) (* 2 radius) (* 2 radius)) ) (begin (gimp-image-select-polygon image CHANNEL-OP-REPLACE 10 (list->vector (list center-x (- center-y radius) (+ center-x radius) center-y (+ center-x radius) (+ center-y radius) (- center-x radius) (+ center-y radius) (- center-x radius) center-y ) ) ) ) ) ;(gimp-image-select-ellipse image CHANNEL-OP-REPLACE (- center-x radius) (- center-y radius) ; (* 2 radius) (* 2 radius)) (gimp-edit-fill bw-layer FOREGROUND-FILL) (gimp-context-set-foreground current-color) ;set it back to current foregroudn color ) ) (gimp-selection-none image) (set! charList (map (lambda (x) (make-string 1 x)) (string->list text))) ;create the list of letters (set! x1 space-width) (while (not (null? charList)) (set! char (car charList)) (set! text-layer (car (gimp-text-layer-new image char font 200 0))) (gimp-image-insert-layer image text-layer 0 0) (set! char-width (car (gimp-drawable-width text-layer))) (set! char-width (* (/(* (/ char-width text-width) (* text-length 7)) (+ (* text-length 7) 2)) (* 2 radius))) (if (= circle-instead TRUE) (begin (set! x2 (+ x1 char-width)) (set! a (abs (- radius x1))) (set! b1 (sqrt (- (pow radius 2) (pow a 2)))) ;calculate y distance in order to combine with x1 to get point on circumference (set! a (abs (- radius x2))) (set! b2 (sqrt (- (pow radius 2) (pow a 2)))) ;calculate y distance in order to combine with x2 to get point on circumference ;(gimp-message (number->string (pow radius 2))) ;(gimp-message (number->string (pow a 2))) ;(gimp-message (number->string (sqrt (- (pow radius 2) (pow a 2))))) ;(gimp-message (number->string b2)) ;(gimp-message (number->string (round(- center-y b2)))) (gimp-item-transform-perspective text-layer (round (+ (- center-x radius) x1)) (round(- center-y b1)) (round(+ (- center-x radius) x2)) (round(- center-y b2)) (round(+ (- center-x radius) x1)) (round(+ center-y b1)) (round(+ (- center-x radius) x2)) (round(+ center-y b2)) ) ) (begin ;(set! x1 (+ x1 space-width)) (set! x2 (+ x1 char-width)) (set! a (abs (- radius x1))) ;(set! b1 (sqrt (- (pow radius 2) (pow a 2)))) ;calculate y distance in order to combine with x1 to get point on circumference (set! b1 (abs(- radius a))) (set! a (abs (- radius x2))) ;(set! b2 (sqrt (- (pow radius 2) (pow a 2)))) ;calculate y distance in order to combine with x2 to get point on circumference (set! b2 (abs(- radius a))) ;(gimp-message (number->string (pow radius 2))) ;(gimp-message (number->string (pow a 2))) ;(gimp-message (number->string (sqrt (- (pow radius 2) (pow a 2))))) ;(gimp-message (number->string b2)) ;(gimp-message (number->string (round(- center-y b2)))) (gimp-item-transform-perspective text-layer (round (+ (- center-x radius) x1)) (round(- center-y b1)) (round(+ (- center-x radius) x2)) (round(- center-y b2)) (round(+ (- center-x radius) x1)) (round(+ center-y radius)) (round(+ (- center-x radius) x2)) (round(+ center-y radius)) ) ) ) (gimp-image-merge-down image text-layer EXPAND-AS-NECESSARY) (set! x1 x2) ; x1 now takes position of x2 (set! charList (cdr charList)) ) ;(gimp-image-undo-enable image) ;DN = NO UNDO (gimp-image-undo-group-end image) ;undo group in one step (gimp-context-pop) (gimp-displays-flush) ) ) (define (script-fu-words-to-shapes image layer text font center-x center-y radius color draw-circle circle-instead ) (let* ( (width (car (gimp-image-width image))) (height (car (gimp-image-height image))) (center-x (if (= center-x -1) (/ width 2) center-x)) (center-y (if (= center-y -1) (/ height 2) center-y)) (words 0) (wordcount 0) (wordwidth 0) (spacewidth 0) (large-radius 0) (X 0) (count 0) (word 0) ) ;(gimp-image-undo-disable image); DN = NO UNDO (gimp-context-push) (gimp-image-undo-group-start image) ;undo-group in one step (set! words (strbreakup text " ")) (set! wordcount (length words)) (set! wordwidth (* radius 2)) (set! spacewidth (/ wordwidth 7)) (set! large-radius (/ (* (/ (* wordwidth wordcount) 7) 8) 2)) (set! X (- center-x large-radius)) (set! count 0) (while (< count wordcount) (set! word (car words)) (set! X (+ X spacewidth)) (set! X (+ X radius)) (script-fu-word-to-shape image layer word font X center-y radius color draw-circle circle-instead) (set! X (+ X radius)) (set! words (cdr words)) (set! count (+ 1 count)) ) ;(gimp-image-undo-enable image) ;DN = NO UNDO (gimp-image-undo-group-end image) ;undo group in one step (gimp-context-pop) (gimp-displays-flush) ) ) (script-fu-register "script-fu-words-to-shapes" ;function name "/Script-Fu/Words To Shapes..." ;menu register "Creates word(s) that fits inside a house(s)/circle(s)" ;description "Tin Tran" ;author name "copyright info and description" ;copyright info or description "2016" ;date "RGB*, GRAY*" ;mode SF-IMAGE "Image" 0 SF-DRAWABLE "Layer" 0 SF-STRING "Word" "Gimp Chat Dot Com" SF-FONT "Font" "Sans Bold" SF-ADJUSTMENT "Center X (-1 = Image X Center)" '(-1 -1 2000 1 10 1 0) SF-ADJUSTMENT "Center Y (-1 = Image Y Center)" '(-1 -1 2000 1 10 1 0) SF-ADJUSTMENT "Radius/Width" '(100 1 2000 1 10 1 0) SF-COLOR "House/Circle Background color" '(255 0 0) SF-TOGGLE "Draw house/circle background" TRUE SF-TOGGLE "Draw Circles instead of Houses" FALSE ;SF-ADJUSTMENT "Gaussian Blur Radius" '(38 1 200 1 10 1 0) ;SF-ADJUSTMENT "Colorize Hue" '(224 0 360 1 10 0 0) ;SF-COLOR "Colorify" '(0 220 223) ;SF-ADJUSTMENT "Levels Gamma" '(0.12 0.10 10.00 1 1 2 0) ;SF-GRADIENT "Gradient 1" "" ;SF-GRADIENT "Gradient 2" "" ;SF-ADJUSTMENT "Border width pixels" '(50 0 1000 1 10 0 0) ;SF-OPTION "Color Curves Preset" (strbreakup (car (python-fu-get-color-curves-presets-names 1)) ",") )