Skip to content

Commit 0c61fc1

Browse files
authored
Handle image being smaller than outline layer
1 parent da8c37c commit 0c61fc1

File tree

1 file changed

+42
-14
lines changed

1 file changed

+42
-14
lines changed

script-fu-outline.scm

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
(script-fu-register
2-
"script-fu-outline" ; func name
3-
"Outline Current Layer..." ; menu label
2+
"script-fu-outline" ;; func name
3+
"Outline Current Layer..." ;; menu label
44
"Creates a simple outline for the current layer"
5-
"Eric Schneider" ; copyright notice
5+
"Eric Schneider" ;; copyright notice
66
"2019 Eric Schneider"
7-
"September 07, 2019 " ; date created
8-
"RGBA" ; image type that the script works on
7+
"September 07, 2019 " ;; date created
8+
"RGBA" ;; image type that the script works on
99
SF-IMAGE "Image" 0
1010
SF-DRAWABLE "Drawable" 0
11-
SF-ADJUSTMENT "Border Size" '(2 1 1000 1 5 0 1) ; a spin button
12-
SF-COLOR "Color" '(0 0 0) ; color variable
13-
SF-TOGGLE "Merge with Layer?" FALSE ; toggle if the layer should get merged with the outline
11+
SF-ADJUSTMENT "Border Size" '(2 1 1000 1 5 0 1) ;; a spin button
12+
SF-COLOR "Color" '(0 0 0) ;; color variable
13+
SF-TOGGLE "Merge with Layer?" FALSE ;; toggle if the layer should get
14+
;; merged with the outline
1415
)
1516
(script-fu-menu-register "script-fu-outline" "<Image>/Edit")
1617
(define (script-fu-outline inImage inLayer inBorderSize inBorderColor doMergeWitLayer)
1718
(let* (
1819
(inLayerName (car (gimp-item-get-name inLayer)))
19-
(currentForegroundColor (car (gimp-context-get-foreground))) ;get the current foreground color to reset later
20+
(currentForegroundColor (car (gimp-context-get-foreground))) ;;get the current foreground
21+
;;color to reset later
2022
(borderLayerHeight (+ (car (gimp-drawable-height inLayer)) inBorderSize))
2123
(borderLayerWidth (+ (car (gimp-drawable-width inLayer)) inBorderSize))
2224
(borderLayerPosition (+ (car (gimp-image-get-item-position inImage inLayer) ) 1))
@@ -32,8 +34,8 @@
3234
LAYER-MODE-NORMAL-LEGACY)))
3335
)
3436
(gimp-image-undo-group-start inImage)
35-
(gimp-selection-clear inImage);remove current selection if there
36-
;initialize the border layer
37+
(gimp-selection-none inImage) ;; remove current selection if there is any
38+
;;; initialize the border layer
3739
(gimp-image-add-layer inImage theBorderLayer borderLayerPosition)
3840
(gimp-layer-set-offsets
3941
theBorderLayer
@@ -46,8 +48,33 @@
4648
(+ borderLayerHeight inBorderSize)
4749
inBorderSize
4850
inBorderSize)
51+
;;; Handle the case of the image being smaller than the layer + outline size
52+
(let*
53+
(
54+
(imageHeight (car(gimp-image-height inImage)))
55+
(imageWidth (car(gimp-image-width inImage)))
56+
(sizeDiffHeight (- borderLayerHeight imageHeight))
57+
(sizeDiffWidth (- borderLayerWidth imageWidth))
58+
)
59+
(when (< imageHeight borderLayerHeight)
60+
(gimp-image-resize
61+
inImage
62+
imageWidth
63+
(+ imageHeight (* sizeDiffHeight 2))
64+
0
65+
sizeDiffHeight)
66+
(set! imageHeight (car(gimp-image-height inImage)))) ;; if we are increasing the height
67+
;; we need to save the new size
68+
(when (< imageWidth borderLayerWidth)
69+
(gimp-image-resize
70+
inImage
71+
(+ imageWidth (* sizeDiffWidth 2))
72+
imageHeight
73+
sizeDiffWidth
74+
0 ) )
75+
)
4976
(plug-in-colortoalpha RUN-NONINTERACTIVE inImage theBorderLayer '(0 0 0))
50-
;select the outline of the current layer
77+
;;; select the outline of the current layer
5178
(gimp-image-select-item inImage CHANNEL-OP-ADD inLayer)
5279
(gimp-selection-grow inImage inBorderSize)
5380
(gimp-context-set-foreground inBorderColor)
@@ -60,14 +87,15 @@
6087
TRUE
6188
0
6289
0)
63-
(gimp-context-set-foreground currentForegroundColor)
64-
(gimp-selection-clear inImage)
6590
(when (equal? doMergeWitLayer TRUE)
6691
(gimp-image-merge-down
6792
inImage
6893
inLayer
6994
CLIP-TO-BOTTOM-LAYER)
7095
)
96+
;;; reset everything that is resettable to the state before
97+
(gimp-context-set-foreground currentForegroundColor)
98+
(gimp-selection-none inImage)
7199
(gimp-displays-flush)
72100
(gimp-image-undo-group-end inImage)
73101
)

0 commit comments

Comments
 (0)