; Original version Elias Pschernig ; Raymond Ostertag 2004/09 ; - changed menu entry ; vim: expandtab : tabstop=3 : shiftwidth=3 : smarttab (define (script-fu-scale-with-colorkey orig-image orig-draw color-key scaling-factor alpha-threshold) (set! orig-width (car (gimp-image-width orig-image))) (set! orig-height (car (gimp-image-height orig-image))) (gimp-image-undo-group-start orig-image) (gimp-selection-none orig-image) ; add alpha channel, select color key, and (if non-empty) clear with transparency (set! orig-layer (car (gimp-image-get-active-layer orig-image))) (gimp-layer-add-alpha orig-layer) (gimp-by-color-select orig-draw color-key 0 CHANNEL-OP-REPLACE FALSE FALSE 0 TRUE) (if (= 0 (car (gimp-selection-bounds orig-image))) 0 (gimp-edit-clear orig-draw)) ; scale the image (set! width (* orig-width scaling-factor)) (set! height (* orig-height scaling-factor)) (gimp-image-scale orig-image width height) (gimp-selection-none orig-image) ; (threshold alpha, select all non-transparent pixels, invert selection (plug-in-threshold-alpha TRUE orig-image orig-draw alpha-threshold) (gimp-by-color-select orig-draw '(0 0 0) 255 CHANNEL-OP-REPLACE FALSE FALSE 0 FALSE) (gimp-selection-invert orig-image) ; if transparent selection, set background to color key and fill with it (set! background (car (gimp-palette-get-background))) (gimp-palette-set-background color-key) (if (= 0 (car (gimp-selection-bounds orig-image))) 0 (gimp-edit-fill orig-draw BACKGROUND-FILL)) (gimp-palette-set-background background) (gimp-selection-none orig-image) (gimp-image-undo-group-end orig-image) (gimp-displays-flush) ) (script-fu-register "script-fu-scale-with-colorkey" "/Script-Fu/Utils/Scale with colorkey..." "Scales an image using colorkeyed transparency. An alpha channel is added, pixels with the colorkey are removed, scaling is done, alpha thresholding is applied and transparent areas are filled again with the color key." "Elias " "2003-2004" "Elias Pschernig" "*" SF-IMAGE "Input Image" 0 SF-DRAWABLE "Input Drawable" 0 SF-COLOR "Color Key" '(255 0 255) SF-VALUE "Scaling Factor" "2" SF-VALUE "Alpha Threshold" "127" )