Skip to content

Commit 6294a5a

Browse files
authored
Border script update
1 parent 8498967 commit 6294a5a

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

egger-BorderC.scm

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
;
2+
; Borders, V2.8
3+
;
4+
; Martin Egger ([email protected])
5+
; (C) 2012, Bern, Switzerland
6+
;
7+
; This script was tested with Gimp 2.10.32
8+
;
9+
; New versions will be distributed from http://registry.gimp.org/ only
10+
;
11+
; This program is free software; you can redistribute it and/or modify
12+
; it under the terms of the GNU General Public License as published by
13+
; the Free Software Foundation; either version 3 of the License, or
14+
; (at your option) any later version.
15+
;
16+
; This program is distributed in the hope that it will be useful,
17+
; but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
; GNU General Public License for more details.
20+
;
21+
; You should have received a copy of the GNU General Public License
22+
; along with this program; if not, see <http://www.gnu.org/licenses>.
23+
;
24+
; Define the function
25+
;
26+
(define (script-fu-Eg-Border-c InImage InLayer InOuterPercentWidth InSymmetric InPortrait InInnerPercent InOuterColor InInnerColor InFeather)
27+
;
28+
(let* (
29+
(TheImage (car (gimp-image-duplicate InImage)))
30+
(TheLayer (car (gimp-image-flatten TheImage)))
31+
(isrgb (car (gimp-drawable-is-rgb TheLayer)))
32+
(TheWidth (car (gimp-image-width TheImage)))
33+
(TheHeight (car (gimp-image-height TheImage)))
34+
;
35+
; W-Border = % of widht, H-Border = % of height (asymmetric)
36+
;
37+
(outer-border-width (/ (* TheWidth InOuterPercentWidth) 100))
38+
(outer-border-top-height (/ (* TheHeight InOuterPercentWidth) 100))
39+
;
40+
; W-Border and H-Border = % of widht (symmetric)
41+
;
42+
(outer-border-top-height (+ (* outer-border-width InSymmetric) (* outer-border-top-height (* -1 (- InSymmetric 1)))))
43+
(outer-border-bottom-height outer-border-top-height)
44+
;
45+
; W-Border and Top-H-Border = % of widht, Bottom-H-Border = (1.41*(TheWidth+2*Border) - Border - TheHeight) (asymmetric)
46+
;
47+
(outer-border-top-height (+ (* outer-border-width InPortrait) (* outer-border-top-height (* -1 (- InPortrait 1)))))
48+
(temp-bottom (- (* 1.414214 (+ TheWidth (* 2 outer-border-width))) TheHeight outer-border-top-height))
49+
(outer-border-bottom-height (+ (* temp-bottom InPortrait) (* outer-border-top-height (* -1 (- InPortrait 1)))))
50+
;
51+
(inner-border-width (/ (* (+ (* TheHeight InPortrait) (* TheWidth (* -1 (- InPortrait 1)))) InInnerPercent) 100))
52+
;
53+
(image-width (+ TheWidth (* 2 outer-border-width)))
54+
(image-height (+ TheHeight outer-border-bottom-height outer-border-top-height))
55+
(Old-FG-Color (car (gimp-context-get-foreground)))
56+
)
57+
58+
(cond
59+
((= isrgb FALSE) (gimp-image-convert-rgb TheImage))
60+
)
61+
(gimp-image-undo-disable TheImage)
62+
(gimp-selection-none TheImage)
63+
(gimp-item-set-name TheLayer "WithBorder")
64+
;
65+
; Generate the border
66+
;
67+
(gimp-image-resize TheImage image-width image-height outer-border-width outer-border-top-height)
68+
;
69+
(let* (
70+
(BorderLayer (car (gimp-layer-new TheImage image-width image-height RGBA-IMAGE "TempLayer" 100 LAYER-MODE-NORMAL)))
71+
)
72+
(gimp-image-insert-layer TheImage BorderLayer 0 -1)
73+
(gimp-edit-clear BorderLayer)
74+
;
75+
(gimp-context-set-feather FALSE)
76+
;
77+
(gimp-image-select-rectangle TheImage CHANNEL-OP-REPLACE 0 0 image-width image-height)
78+
(gimp-image-select-rectangle TheImage CHANNEL-OP-SUBTRACT outer-border-width outer-border-top-height TheWidth TheHeight)
79+
(gimp-context-set-foreground InOuterColor)
80+
(gimp-edit-fill BorderLayer FILL-FOREGROUND)
81+
;
82+
(cond
83+
((> InInnerPercent 0)
84+
(begin
85+
(gimp-context-set-feather InFeather)
86+
(gimp-context-set-feather-radius (* 1.4 inner-border-width) (* 1.4 inner-border-width))
87+
(gimp-image-select-rectangle TheImage CHANNEL-OP-REPLACE (- outer-border-width inner-border-width) (- outer-border-top-height inner-border-width) (+ TheWidth (* inner-border-width 2)) (+ TheHeight (* inner-border-width 2)))
88+
(gimp-context-set-feather FALSE)
89+
(gimp-image-select-rectangle TheImage CHANNEL-OP-SUBTRACT outer-border-width outer-border-top-height TheWidth TheHeight)
90+
(gimp-context-set-foreground InInnerColor)
91+
(gimp-edit-fill BorderLayer FILL-FOREGROUND)
92+
)
93+
)
94+
)
95+
(gimp-image-merge-down TheImage BorderLayer CLIP-TO-IMAGE)
96+
)
97+
;
98+
(gimp-selection-none TheImage)
99+
(gimp-display-new TheImage)
100+
(gimp-image-undo-enable TheImage)
101+
(gimp-context-set-foreground Old-FG-Color)
102+
)
103+
;
104+
; Finish work
105+
;
106+
(gimp-displays-flush)
107+
;
108+
)
109+
;
110+
; Register the function with the GIMP
111+
;
112+
(script-fu-register
113+
"script-fu-Eg-Border-c"
114+
"Egger Border C"
115+
"Generate a border around an image. \nfile:egger-BorderC.scm"
116+
"Martin Egger ([email protected])"
117+
"Martin Egger, Bern, Switzerland"
118+
"28.12.2012"
119+
"RGB* GRAY*"
120+
SF-IMAGE "The Image" 0
121+
SF-DRAWABLE "The Layer" 0
122+
SF-ADJUSTMENT "Outer border size (width in percent)" '(6 1.0 100 1.0 0 2 0)
123+
SF-TOGGLE "Use symmetric outer borders" FALSE
124+
SF-TOGGLE "Use portrait style border" FALSE
125+
SF-ADJUSTMENT "Inner border size (in percent)" '(2.50 0.0 10.0 0.1 0 2 0)
126+
SF-COLOR "Outer border color" '(255 255 255)
127+
SF-COLOR "Inner border color" '(0 0 0)
128+
SF-TOGGLE "Feather inner border" FALSE
129+
)
130+
;
131+
(script-fu-menu-register "script-fu-Eg-Border-c"
132+
"<Toolbox>/Script-Fu/Decor/")
133+
;

0 commit comments

Comments
 (0)