-
Notifications
You must be signed in to change notification settings - Fork 1
/
FU_edges_frames.scm
431 lines (400 loc) · 16.8 KB
/
FU_edges_frames.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
; FU_edges_frames.scm
; version 2.8 [gimphelp.org]
; last modified/tested by Paul Sherman
; 02/14/2014 on GIMP-2.8.10
;
; modified 01/06/2008
; modified Wed Oct 1, 2008 by Paul Sherman
; modified again 11/20/2008 for gimp-2.6
; 02/14/2014 convwert to RGB if needed
; 05/29/2020 converted to work on Gimp 2.10.18
;==============================================================
;
; Installation:
; This script should be placed in the user or system-wide script folder.
;
; Windows Vista/7/8)
; C:\Program Files\GIMP 2\share\gimp\2.0\scripts
; or
; C:\Users\YOUR-NAME\.gimp-2.8\scripts
;
; Windows XP
; C:\Program Files\GIMP 2\share\gimp\2.0\scripts
; or
; C:\Documents and Settings\yourname\.gimp-2.8\scripts
;
; Linux
; /home/yourname/.gimp-2.8/scripts
; or
; Linux system-wide
; /usr/share/gimp/2.0/scripts
;
;==============================================================
;
; LICENSE
;
; 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.
;
; You should have received a copy of the GNU General Public License
; along with this program. If not, see <http://www.gnu.org/licenses/>.
;
;==============================================================
; Original information
;
; edge_sign.scm --- prepare photograph for publishing on Internet
; originally frame.scm
;
; Copyright (C) 2006 by Walter C. Pelissero
;
; Author: Walter C. Pelissero <walter@pelissero.de>
;
; These scripts are suitable for publishing photographs on Internet.
; They resizes a picture, then add a border, (one of the commands
; drops a shadow as well) and add the author's name in the bottom
; right corner.
;
; There are three commands script-fu-frame-modern, -poster and
; -negative. The former rounds the corners and drops a shadow on a
; white background. The latter rounds the corners and adds a black
; border. Both add a signature which has to be modified in the
; script as Script-Fu is very limited and doesn't allow for any
; default values that are not constant.
;==============================================================
(define (FU-frame-hover image drawable width signature-text font-name)
(if (<= width 128.0)
(begin
;(gimp-message "Width set too small. Reset to 128")
(set! width 128.0)
)
(begin
;(gimp-message "Width kept.")
)
)
(gimp-display-new
(FU-frame-hover-batch image drawable width signature-text font-name))
(gimp-displays-flush)
)
(define (FU-frame-negative image drawable targetwidth signature-text font-name)
(let* (
(revisedwidth 50.0)
)
;(gimp-message (number->string targetwidth))
(if (<= targetwidth 128.0)
(begin
;(gimp-message "Width set too small. Reset to 128")
(set! targetwidth 128.0)
)
(begin
;(gimp-message "Width kept.")
)
)
(gimp-display-new
(FU-frame-negative-batch image drawable targetwidth signature-text font-name))
(gimp-displays-flush)
)
)
(define (FU-frame-poster image drawable width border-colour signature-text font-name)
(if (<= width 128.0)
(begin
;(gimp-message "Width set too small. Reset to 128")
(set! width 128.0)
)
(begin
;(gimp-message "Width kept.")
)
)
(gimp-display-new
(FU-frame-poster-batch image drawable width border-colour signature-text font-name))
(gimp-displays-flush)
)
(define (%top-layer image)
(aref (cadr (gimp-image-get-layers image)) 0)
)
(define (FU-frame-hover-batch image drawable width signature-text font-name)
(let* (
(new-image (car (gimp-image-duplicate image)))
(drawable (car (gimp-image-get-active-drawable new-image)))
(height (* (car (gimp-image-height new-image))
(/ width (car (gimp-image-width new-image)))))
;; just an index of dimension
(size (/ (sqrt (* width height)) 20))
(foreground (car (gimp-context-get-foreground)))
(background (car (gimp-context-get-background)))
)
(gimp-image-undo-group-start new-image)
(if (not (= RGB (car (gimp-image-base-type new-image))))
(gimp-image-convert-rgb new-image)
)
(script-fu-guides-remove new-image drawable)
(gimp-image-scale new-image width height)
(plug-in-unsharp-mask RUN-NONINTERACTIVE image drawable
(* size 0.15) ; radius (constant found empirically)
0.3 ; amount
0 ; threshold
)
(gimp-context-set-foreground '(0 0 0))
(gimp-context-set-background '(255 255 255))
(script-fu-round-corners new-image
drawable
(trunc (* size 1.3)) ; edge radius ; was /2
TRUE ; add drop shadow
(trunc (/ size 3)) ; shadow x offset
(trunc (/ size 3)) ; shadow y offset
(trunc (/ size 2)) ; shadow blur radius
TRUE ; add background ; was T
;; don't make another copy as we just made one
FALSE)
(if (> size 20)
(begin
;(gimp-message "size >20")
(gimp-image-set-active-layer new-image (%top-layer new-image))
(let* ((text-layer (car (gimp-text-fontname new-image
-1 ; drawable, -1 = new layer
0
0
signature-text
(/ size 6) ; border
TRUE ; antialias
(max 10 (/ size 2)) ; text size
PIXELS ; size unit
font-name)))
(text-width (car (gimp-drawable-width text-layer)))
(text-height (car (gimp-drawable-height text-layer)))
)
(gimp-layer-set-offsets text-layer
(- (car (gimp-image-width new-image)) text-width (log size))
(- (car (gimp-image-height new-image)) text-height))
)
)
(begin
(gimp-message "Size small. No signature in border. Use 512 or higher.")
)
)
(gimp-image-merge-visible-layers new-image 0)
(gimp-context-set-foreground foreground)
(gimp-context-set-background background)
(gimp-image-undo-group-end new-image)
;; return the new image so that batch scripts can do something
;; with it
new-image)
)
(define (FU-frame-negative-batch image drawable width signature-text font-name)
(let* (
(new-image (car (gimp-image-duplicate image)))
(drawable (car (gimp-image-get-active-drawable new-image)))
(height (* (car (gimp-image-height new-image))
(/ width (car (gimp-image-width new-image)))))
(size (/ (sqrt (* width height)) 20))
(foreground (car (gimp-context-get-foreground)))
(background (car (gimp-context-get-background)))
(black-layer (car (gimp-layer-new new-image
width ; (car (gimp-image-width new-image))
height ; (car (gimp-image-height new-image))
RGB-IMAGE
"Black layer"
100
LAYER-MODE-NORMAL)))
)
(gimp-image-undo-group-start new-image)
(if (not (= RGB (car (gimp-image-base-type new-image))))
(gimp-image-convert-rgb new-image)
)
(script-fu-guides-remove new-image drawable)
(gimp-image-scale new-image width height)
(plug-in-unsharp-mask RUN-NONINTERACTIVE image drawable
(* size 0.15) ; radius
0.3 ; amount
0 ; threshold
)
(gimp-context-set-foreground '(0 0 0)) ; ws 250 250 250
(gimp-context-set-background '(0 0 0))
(script-fu-round-corners new-image
drawable
(trunc (* size 0.8)) ; edge radius ; was / 3
FALSE ; no shadow
0 ; shadow x offset
0 ; shadow y offset
0 ; shadow blur radius
FALSE ; add background
;; don't make another copy as we just made one
FALSE)
(gimp-image-insert-layer new-image black-layer 0 1)
(gimp-edit-fill black-layer FILL-BACKGROUND)
(gimp-context-set-foreground '(200 200 200))
;(gimp-display-new new-image)
;(quit)
(gimp-image-merge-visible-layers new-image 0)
(let ((background-layer (%top-layer new-image)))
(if (> size 20)
(begin
(let* (
(text-layer (car (gimp-text-fontname new-image
-1 ; drawable, -1 = new layer
0
0
signature-text
1 ; border
TRUE ; antialias
(max 10 (/ size 2)) ; text size
PIXELS ; size unit
font-name)))
(text-width (car (gimp-drawable-width text-layer)))
(text-height (car (gimp-drawable-height text-layer)))
)
(script-fu-addborder new-image background-layer
text-height text-height '(0 0 0) 0)
(gimp-layer-set-offsets text-layer
(- (car (gimp-image-width new-image)) text-width (log size))
(- (car (gimp-image-height new-image)) text-height))
(gimp-image-raise-item-to-top new-image text-layer)
)
(gimp-image-merge-visible-layers new-image 0)
)
(begin
(gimp-message "Size small. No Signature in border. Use 512 or higher.")
;(gimp-message (number->string size))
(script-fu-addborder new-image background-layer
(round (* size 0.75)) (round (* size 0.75)) '(0 0 0) 0)
)
)
)
(gimp-context-set-foreground foreground)
(gimp-context-set-background background)
(gimp-image-undo-group-end new-image)
;; return the new image so that batch scripts can do something
;; with it
new-image
)
)
(define (FU-frame-poster-batch image drawable width border-colour signature-text font-name)
(let* (
(new-image (car (gimp-image-duplicate image)))
(drawable (car (gimp-image-get-active-drawable new-image)))
(height (* (car (gimp-image-height new-image))
(/ width (car (gimp-image-width new-image)))))
(size (/ (sqrt (* width height)) 20))
(inverted-border-colour (mapcar (lambda (value)
(- 255 value))
border-colour))
(foreground (car (gimp-context-get-foreground)))
(background (car (gimp-context-get-background)))
)
(gimp-image-undo-group-start new-image)
(if (not (= RGB (car (gimp-image-base-type new-image))))
(gimp-image-convert-rgb new-image)
)
(script-fu-guides-remove new-image drawable)
(gimp-image-scale new-image width height)
(plug-in-unsharp-mask RUN-NONINTERACTIVE image drawable
(* size 0.15) ; radius
0.3 ; amount
0 ; threshold
)
(gimp-context-set-foreground inverted-border-colour)
(gimp-context-set-background border-colour)
(let (
(thickness (max 1 (trunc (/ (log size) 2))))
)
(script-fu-addborder new-image (%top-layer new-image)
thickness thickness
inverted-border-colour
0)
)
(gimp-image-merge-visible-layers new-image 0)
(let ((background-layer (%top-layer new-image)))
(if (> size 20)
(begin
(let* (
(text-layer (car (gimp-text-fontname new-image
-1 ; drawable, -1 = new layer
0
0
signature-text
1 ; border
TRUE ; antialias
;; text size (cursive fonts need more space)
(max 10 (/ size 1.5))
PIXELS ; size unit
font-name)))
(text-width (car (gimp-drawable-width text-layer)))
(text-height (car (gimp-drawable-height text-layer)))
)
(script-fu-addborder new-image background-layer
text-height text-height border-colour 0)
(gimp-layer-set-offsets text-layer
(- (car (gimp-image-width new-image)) text-width (log size))
(- (car (gimp-image-height new-image)) text-height))
(gimp-image-raise-item-to-top new-image text-layer)
)
)
(begin
(gimp-message "Size small. No signature in border. Use 512 or higher.")
(script-fu-addborder new-image background-layer
size size border-colour 0)
)
)
)
(gimp-image-merge-visible-layers new-image 0)
(gimp-context-set-foreground foreground)
(gimp-context-set-background background)
(gimp-image-undo-group-end new-image)
;; return the new image so that batch scripts can do something
;; with it
new-image
)
)
(script-fu-register "FU-frame-hover"
"Frame like a hover with drop shadow and round corners..."
"Resize, frame and sign a photograph for publishing on Internet (\"hover\" style). Creates a new image. \nfile:FU_edges_frames.scm"
"Walter Pelissero <walter@pelissero.de>"
"Walter Pelissero"
"2006/07/13"
"*"
SF-IMAGE "Image" 0
SF-DRAWABLE "Drawable" 0
SF-ADJUSTMENT "Image width" '(640 128 4096 128 10 0 1)
SF-STRING "Signature" "Your Name"
SF-FONT "Font" "sans"
)
(script-fu-menu-register "FU-frame-hover"
"<Toolbox>/Script-Fu/Edges")
(script-fu-register "FU-frame-negative"
"Frame like a negative slide with round corners..."
"Resize, frame and sign a photograph for publishing on Internet (\"slide\" style). Creates a new image. \nfile:FU_edges_frames.scm"
"Walter Pelissero <walter@pelissero.de>"
"Walter Pelissero"
"2006/07/13"
"*"
SF-IMAGE "Image" 0
SF-DRAWABLE "Drawable" 0
SF-ADJUSTMENT "Image target width" '(640 128 4096 128 10 0 1)
SF-STRING "Signature" "Your Name"
SF-FONT "Font" "sans"
)
(script-fu-register "FU-frame-poster"
"Frame like poster with straight corners..."
"Resize, frame and sign a photograph for publishing on Internet (\"poster\" style). Creates a new image. \nfile:FU_edges_frames.scm"
"Walter Pelissero <walter@pelissero.de>"
"Walter Pelissero"
"2006/09/06"
"*"
SF-IMAGE "Image" 0
SF-DRAWABLE "Drawable" 0
SF-ADJUSTMENT "Image target width" '(640 128 4096 128 10 0 1)
SF-COLOR "Border colour" '(0 0 0)
SF-STRING "Signature" "Your Name"
SF-FONT "Font" "sans"
)
(script-fu-menu-register "FU-frame-negative"
"<Toolbox>/Script-Fu/Edges")
(script-fu-menu-register "FU-frame-poster"
"<Toolbox>/Script-Fu/Edges")
;end of script