; scale steps down v0.22 by Con Kolivas ; ; This program is free software; you can redistribute it and/or modify it ; under the terms of the GNU General Public License as published by the Free ; Software Foundation; either version 3 of the License, or (at your option) ; any later version. See COPYING for more details. (define (script-fu-scale-steps-down image drawable mwidth mheight stepsize flatten interpolation recursion) (gimp-image-undo-group-start image) (if (= flatten TRUE) (set! drawable (car(gimp-image-flatten image))) ) (let*( (sel_width 0) (sel_height 0) (new_width 0) (new_height 0) (new_x1 0) (new_x2 0) (new_y1 0) (new_y2 0) (orig_height 0) (orig_width 0) (half_nextstep 0.0) (possible_width 0) (possible_height 0) ) (set! orig_height (car (gimp-drawable-height drawable))) (set! orig_width (car (gimp-drawable-width drawable))) (set! half_nextstep (* 1.5 stepsize)) (while (and (> (car (gimp-drawable-height drawable)) mheight) (> (car (gimp-drawable-width drawable)) mwidth) ) (set! sel_width (car (gimp-drawable-width drawable))) (set! sel_height (car (gimp-drawable-height drawable))) (set! new_width (/ sel_width (/ (+ 100 stepsize) 100))) (set! new_height (/ sel_height (/ (+ 100 stepsize) 100))) (set! possible_width (/ sel_width (/ (+ 100 half_nextstep) 100))) (set! possible_height (/ sel_height (/ (+ 100 half_nextstep) 100))) (if (< possible_width mwidth) (begin (set! new_width mwidth) (set! new_height (* orig_height (/ mwidth orig_width))) ) ) (if (< possible_height mheight) (begin (set! new_height mheight) (set! new_width (* orig_width (/ mheight orig_height))) ) ) (if (< new_width mwidth) (begin (set! new_width mwidth) (set! new_height (* orig_height (/ mwidth orig_width))) ) ) (if (< new_height mheight) (begin (set! new_height mheight) (set! new_width (* orig_width (/ mheight orig_height))) ) ) (set! new_x1 0) (set! new_y1 0) (set! new_x2 new_width) (set! new_y2 new_height) (gimp-drawable-transform-scale drawable new_x1 new_y1 new_x2 new_y2 0 interpolation 1 recursion TRANSFORM-RESIZE-CROP ; TRANSFORM-RESIZE-CROP-WITH-ASPECT ; TRANSFORM-RESIZE-CLIP ; TRANSFORM-RESIZE-ADJUST ) (gimp-image-crop image new_width new_height 0 0) ) (if (= flatten TRUE) (gimp-image-flatten image)) (gimp-image-undo-group-end image) (gimp-displays-flush) ) ) (script-fu-register "script-fu-scale-steps-down" "Scale in steps down" "Scale in steps until one of width or height is smaller than the supplied values" "C.Kolivas" "(c) 2010 based on work (c) 2008 K.-M. Hansche" "2010-07-15" "RGB* GRAY*" SF-IMAGE "image" 0 SF-DRAWABLE "drawable" 0 SF-ADJUSTMENT "Min Width" '(800 10 99999 1 50 0 1) SF-ADJUSTMENT "Min Height" '(1200 10 99999 1 50 0 1) SF-ADJUSTMENT "Stepsize in percent" '(10 1 20 1 2 0 1) SF-TOGGLE "Flatten Image" TRUE SF-ENUM "Interpolation (Scaling)" '("InterpolationType" "lanczos") SF-ADJUSTMENT "Recursion level (Scaling)" '(4 1 10 1 1 0 1) ) (script-fu-menu-register "script-fu-scale-steps-down" "/Script-Fu")