Popular Posts

Sunday, April 10, 2011

Toon Effect: Photo effect using the Gimp.

Toon Effect:

This will turn a photo into a Toon effect:

Here is the code -->
;*************************************************************************************** 
; Toon Image script for GIMP 2.2
; --------------------------------------------------------------------

(define (script-fu-Toon
        img
        drawable
    )

    (gimp-undo-push-group-start img)
    (let*    (
            (width (car (gimp-drawable-width drawable)))
            (height (car (gimp-drawable-height drawable)))
            (layer51 (car (gimp-layer-new-from-drawable drawable img)))
            (layer50 (car (gimp-layer-new-from-drawable drawable img)))
            (layerp0 (car (gimp-layer-new-from-drawable drawable img)))
            (layerp1 (car (gimp-layer-new-from-drawable drawable img)))
            (layerbl (car (gimp-layer-new-from-drawable drawable img)))
        )
        (gimp-image-add-layer img layer51 -1)
 
        (let*    (
                (image-type (car (gimp-image-base-type img)))
                (smoothness 8)
                (fidelity 5)
                (colors 16)
                (blur (/ (* width smoothness 0.001 ) fidelity))
                (count 0)
                (layer-lock (car (gimp-layer-get-lock-alpha layer51)))
                (layer-type (car (gimp-drawable-type layer51)))
                (layer-temp1 (car (gimp-layer-new img width height layer-type "temp1" 100 NORMAL-MODE)))
                (img2 (car (gimp-image-new width height image-type)))
                (layer-temp2 (car (gimp-layer-new img2 width height layer-type "temp2" 100 NORMAL-MODE)))
            )
            (gimp-drawable-fill layer-temp1 TRANS-IMAGE-FILL)
            (gimp-image-add-layer img layer-temp1 -1)
            (gimp-edit-copy layer51)
            (gimp-floating-sel-anchor (car (gimp-edit-paste layer-temp1 0)))
            (gimp-layer-set-lock-alpha layer-temp1 TRUE)
            (while (< count fidelity)
                (plug-in-gauss 1 img layer-temp1 blur blur 0)
                (set! count (+ count 1))
            )
            (gimp-layer-set-lock-alpha layer-temp1 layer-lock)
            (gimp-levels layer-temp1 0 0 182 1.0 0 255)
            (gimp-edit-copy layer-temp1)
            (gimp-image-add-layer img2 layer-temp2 -1)
            (gimp-drawable-fill layer-temp2 TRANS-IMAGE-FILL)
            (gimp-floating-sel-anchor (car (gimp-edit-paste layer-temp2 0)))
            (gimp-image-convert-indexed img2 0 0 colors 0 0 "0")
            (gimp-edit-copy layer-temp2)
            (gimp-image-delete img2)
            (gimp-layer-add-alpha layer-temp1)
            (gimp-floating-sel-anchor (car (gimp-edit-paste layer-temp1 0)))
        )
        (gimp-image-add-layer img layerp0 -1)
        (gimp-image-add-layer img layerp1 -1)
        (plug-in-gauss 1 img layerp1 7.0 7.0 1)
        (gimp-layer-set-opacity layerp1 50.0)
        (gimp-invert layerp1)
        (gimp-image-merge-down img layerp1 0)
        (set! layerp0 (car (gimp-image-get-active-layer img)))
        (gimp-levels layerp0 0 100 155 1.00 0 255)
        (gimp-desaturate-full layerp0 1)
        (gimp-levels layerp0 0 39 128 .77 0 255)
        (gimp-levels layerp0 0 184 205 .32 0 255)
        (gimp-layer-set-mode layerp0 17)
        (gimp-image-add-layer img layer50 -1)
        (plug-in-normalize 1 img layer50)
        (gimp-threshold layer50 128 255)
        (gimp-layer-set-opacity layer50 40.0)
        (gimp-layer-set-mode layer50 17)
        (gimp-image-merge-down img layerp0 0)
        (set! drawable (car (gimp-image-get-active-layer img)))
        (gimp-image-merge-down img drawable 0)
        (gimp-image-merge-down img layer50 0)
        (set! drawable (car (gimp-image-get-active-layer img)))
        (gimp-layer-set-name drawable "Toon")
        (gimp-undo-push-group-end img)
        (gimp-displays-flush)
    )
)
(script-fu-register
 "script-fu-Toon" _"<Image>/Script-Fu/Artistic/Toon"
 "Toon a Picture"
 ""
 ""
 "2011"
 "RGB* GRAY*"
 SF-IMAGE "Image"    0
 SF-DRAWABLE "Drawable" 0
)
Toon 

No comments:

Post a Comment