Skip to content

Instantly share code, notes, and snippets.

@dchawisher
Last active July 8, 2023 21:29
Show Gist options
  • Select an option

  • Save dchawisher/3e49ec3261454dec592ba6665f11cb49 to your computer and use it in GitHub Desktop.

Select an option

Save dchawisher/3e49ec3261454dec592ba6665f11cb49 to your computer and use it in GitHub Desktop.
GIMP Plugin for "torn paper" effect
(define (tear image drawable)
(gimp-image-undo-group-start image)
(let* (
(backdrop (car (gimp-layer-new image (car (gimp-image-width image)) (car (gimp-image-height image)) RGBA-IMAGE "Torn Paper Scratch Layer" 100 NORMAL-MODE)))
(source (car (gimp-layer-copy drawable TRUE)))
(twidth (car (gimp-image-width image)))
(tscale0 (* twidth 0.002))
(tscale1 (* twidth 0.001))
(tscale2 (* twidth 0.001))
(tscale3 (* twidth 0.003))
(gran1 44)
(gran2 10)
(gran3 2)
(smooth1 (+ 4.5(* tscale1 0.15)))
(smooth2 (+ 3(* tscale3 0.04)))
)
(gimp-image-add-layer image source 0)
(gimp-image-add-layer image backdrop 1)
(gimp-drawable-set-visible source TRUE)
(gimp-drawable-set-visible backdrop TRUE)
(gimp-drawable-fill backdrop TRANSPARENT-FILL)
(gimp-selection-grow image tscale0)
(script-fu-distress-selection image source 127 tscale1 gran1 smooth1 TRUE TRUE)
(script-fu-distress-selection image source 127 tscale2 gran2 smooth2 TRUE TRUE)
(script-fu-distress-selection image source 127 tscale3 gran3 smooth2 TRUE TRUE)
(let (
(mask (car (gimp-layer-create-mask source ADD-BLACK-MASK))))
(gimp-context-set-foreground '(255 255 255)) ;Add a mask so that only the selected portion of the layer is visible.
(gimp-layer-add-mask source mask)
(gimp-edit-fill mask FOREGROUND-FILL)
)
)
(let (
(final
(car (gimp-image-merge-down image (vector-ref (cadr (gimp-image-get-layers image)) 0) EXPAND-AS-NECESSARY)))
) ;Merge and crop the layers.
(plug-in-autocrop-layer FALSE image final)
(gimp-drawable-set-name final "New Torn Paper Layer")
(gimp-edit-copy final)
)
(gimp-selection-none image)
(gimp-image-undo-group-end image)
(gimp-displays-flush)
)
(script-fu-register
"tear"
"Tear Paper Layer"
"Creates a layer with the selection torn out as if made of paper."
"David Hawisher"
"public domain"
"July 7, 2023"
"RGB*"
SF-IMAGE "An image" 0
SF-DRAWABLE "A drawable" 0)
(script-fu-menu-register "tear" "<Image>/Filters")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment