|
1 | 1 | (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 |
4 | 4 | "Creates a simple outline for the current layer"
|
5 |
| - "Eric Schneider" ; copyright notice |
| 5 | + "Eric Schneider" ;; copyright notice |
6 | 6 | "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 |
9 | 9 | SF-IMAGE "Image" 0
|
10 | 10 | 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 |
14 | 15 | )
|
15 | 16 | (script-fu-menu-register "script-fu-outline" "<Image>/Edit")
|
16 | 17 | (define (script-fu-outline inImage inLayer inBorderSize inBorderColor doMergeWitLayer)
|
17 | 18 | (let* (
|
18 | 19 | (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 |
20 | 22 | (borderLayerHeight (+ (car (gimp-drawable-height inLayer)) inBorderSize))
|
21 | 23 | (borderLayerWidth (+ (car (gimp-drawable-width inLayer)) inBorderSize))
|
22 | 24 | (borderLayerPosition (+ (car (gimp-image-get-item-position inImage inLayer) ) 1))
|
|
32 | 34 | LAYER-MODE-NORMAL-LEGACY)))
|
33 | 35 | )
|
34 | 36 | (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 |
37 | 39 | (gimp-image-add-layer inImage theBorderLayer borderLayerPosition)
|
38 | 40 | (gimp-layer-set-offsets
|
39 | 41 | theBorderLayer
|
|
46 | 48 | (+ borderLayerHeight inBorderSize)
|
47 | 49 | inBorderSize
|
48 | 50 | 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 | + ) |
49 | 76 | (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 |
51 | 78 | (gimp-image-select-item inImage CHANNEL-OP-ADD inLayer)
|
52 | 79 | (gimp-selection-grow inImage inBorderSize)
|
53 | 80 | (gimp-context-set-foreground inBorderColor)
|
|
60 | 87 | TRUE
|
61 | 88 | 0
|
62 | 89 | 0)
|
63 |
| - (gimp-context-set-foreground currentForegroundColor) |
64 |
| - (gimp-selection-clear inImage) |
65 | 90 | (when (equal? doMergeWitLayer TRUE)
|
66 | 91 | (gimp-image-merge-down
|
67 | 92 | inImage
|
68 | 93 | inLayer
|
69 | 94 | CLIP-TO-BOTTOM-LAYER)
|
70 | 95 | )
|
| 96 | + ;;; reset everything that is resettable to the state before |
| 97 | + (gimp-context-set-foreground currentForegroundColor) |
| 98 | + (gimp-selection-none inImage) |
71 | 99 | (gimp-displays-flush)
|
72 | 100 | (gimp-image-undo-group-end inImage)
|
73 | 101 | )
|
|
0 commit comments