; 0.1 : Original version ; 0.2 : Ported to Gimp2 by Raymond Ostertag (define (script-fu-selection-copy-resize image drawable width) (let* ((scale nil) (new-image nil) (new-layer nil) (new-wd nil) (new-hi nil) (pasted nil) (bounds (gimp-selection-bounds image)) (select.x1 (nth 1 bounds)) (select.y1 (nth 2 bounds)) (select.x2 (nth 3 bounds)) (select.y2 (nth 4 bounds))) ; copy the selection (gimp-edit-copy drawable) ; do some math (set! scale (/ width (- select.x2 select.x1))) (set! new-wd (* scale (- select.x2 select.x1))) (set! new-hi (* scale (- select.y2 select.y1))) ; create a new image and give it a layer (set! new-image (car (gimp-image-new new-wd new-hi RGB))) (set! new-layer (car (gimp-layer-new new-image new-wd new-hi RGB-IMAGE "selection" 100 NORMAL-MODE))) (gimp-image-add-layer new-image new-layer -1) ; paste and scale the selection (set! pasted (car (gimp-edit-paste new-layer FALSE))) (gimp-layer-scale pasted new-wd new-hi TRUE) (gimp-image-flatten new-image) ; display the result (gimp-display-new new-image) (gimp-displays-flush) new-image )) (script-fu-register "script-fu-selection-copy-resize" "/Script-Fu/Selection/Copy&Resize..." "Copies a selection to a new image and resizes it to the specified width" "John Beppu " "John Beppu" "August 28, 2002" "*" SF-IMAGE "image" 0 SF-DRAWABLE "drawable" 0 SF-VALUE "width" "400") ; gimp-selection-bounds ; gimp-edit-copy ; gimp-image-new ; gimp-layer-new ; gimp-image-add-layer ; gimp-edit-paste ; gimp-layer-scale ; gimp-image-flatten ; gimp-display-new ; gimp-displays-flush