Skip to content

Commit

Permalink
Handle image being smaller than outline layer
Browse files Browse the repository at this point in the history
  • Loading branch information
tailoric authored Sep 8, 2019
1 parent da8c37c commit 0c61fc1
Showing 1 changed file with 42 additions and 14 deletions.
56 changes: 42 additions & 14 deletions script-fu-outline.scm
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
(script-fu-register
"script-fu-outline" ; func name
"Outline Current Layer..." ; menu label
"script-fu-outline" ;; func name
"Outline Current Layer..." ;; menu label
"Creates a simple outline for the current layer"
"Eric Schneider" ; copyright notice
"Eric Schneider" ;; copyright notice
"2019 Eric Schneider"
"September 07, 2019 " ; date created
"RGBA" ; image type that the script works on
"September 07, 2019 " ;; date created
"RGBA" ;; image type that the script works on
SF-IMAGE "Image" 0
SF-DRAWABLE "Drawable" 0
SF-ADJUSTMENT "Border Size" '(2 1 1000 1 5 0 1) ; a spin button
SF-COLOR "Color" '(0 0 0) ; color variable
SF-TOGGLE "Merge with Layer?" FALSE ; toggle if the layer should get merged with the outline
SF-ADJUSTMENT "Border Size" '(2 1 1000 1 5 0 1) ;; a spin button
SF-COLOR "Color" '(0 0 0) ;; color variable
SF-TOGGLE "Merge with Layer?" FALSE ;; toggle if the layer should get
;; merged with the outline
)
(script-fu-menu-register "script-fu-outline" "<Image>/Edit")
(define (script-fu-outline inImage inLayer inBorderSize inBorderColor doMergeWitLayer)
(let* (
(inLayerName (car (gimp-item-get-name inLayer)))
(currentForegroundColor (car (gimp-context-get-foreground))) ;get the current foreground color to reset later
(currentForegroundColor (car (gimp-context-get-foreground))) ;;get the current foreground
;;color to reset later
(borderLayerHeight (+ (car (gimp-drawable-height inLayer)) inBorderSize))
(borderLayerWidth (+ (car (gimp-drawable-width inLayer)) inBorderSize))
(borderLayerPosition (+ (car (gimp-image-get-item-position inImage inLayer) ) 1))
Expand All @@ -32,8 +34,8 @@
LAYER-MODE-NORMAL-LEGACY)))
)
(gimp-image-undo-group-start inImage)
(gimp-selection-clear inImage);remove current selection if there
;initialize the border layer
(gimp-selection-none inImage) ;; remove current selection if there is any
;;; initialize the border layer
(gimp-image-add-layer inImage theBorderLayer borderLayerPosition)
(gimp-layer-set-offsets
theBorderLayer
Expand All @@ -46,8 +48,33 @@
(+ borderLayerHeight inBorderSize)
inBorderSize
inBorderSize)
;;; Handle the case of the image being smaller than the layer + outline size
(let*
(
(imageHeight (car(gimp-image-height inImage)))
(imageWidth (car(gimp-image-width inImage)))
(sizeDiffHeight (- borderLayerHeight imageHeight))
(sizeDiffWidth (- borderLayerWidth imageWidth))
)
(when (< imageHeight borderLayerHeight)
(gimp-image-resize
inImage
imageWidth
(+ imageHeight (* sizeDiffHeight 2))
0
sizeDiffHeight)
(set! imageHeight (car(gimp-image-height inImage)))) ;; if we are increasing the height
;; we need to save the new size
(when (< imageWidth borderLayerWidth)
(gimp-image-resize
inImage
(+ imageWidth (* sizeDiffWidth 2))
imageHeight
sizeDiffWidth
0 ) )
)
(plug-in-colortoalpha RUN-NONINTERACTIVE inImage theBorderLayer '(0 0 0))
;select the outline of the current layer
;;; select the outline of the current layer
(gimp-image-select-item inImage CHANNEL-OP-ADD inLayer)
(gimp-selection-grow inImage inBorderSize)
(gimp-context-set-foreground inBorderColor)
Expand All @@ -60,14 +87,15 @@
TRUE
0
0)
(gimp-context-set-foreground currentForegroundColor)
(gimp-selection-clear inImage)
(when (equal? doMergeWitLayer TRUE)
(gimp-image-merge-down
inImage
inLayer
CLIP-TO-BOTTOM-LAYER)
)
;;; reset everything that is resettable to the state before
(gimp-context-set-foreground currentForegroundColor)
(gimp-selection-none inImage)
(gimp-displays-flush)
(gimp-image-undo-group-end inImage)
)
Expand Down

0 comments on commit 0c61fc1

Please sign in to comment.