GIMP Script-fu
Check-in [b31278b52c]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
SHA1 Hash:b31278b52c983c7e27a038a4b62ce4c70fd93d23
Date: 2012-03-31 09:12:16
User: saul
Comment:Added fit-in-selection to my trunk.
Tags And Properties
Changes
hide diffs unified diffs patch

Added sg-layer-fit-in-selection.scm

> 1 ; This program is free software; you can redistribute it and/or modify > 2 ; it under the terms of the GNU General Public License as published by > 3 ; the Free Software Foundation; either version 2 of the License, or > 4 ; (at your option) any later version. > 5 ; > 6 ; This program is distributed in the hope that it will be useful, > 7 ; but WITHOUT ANY WARRANTY; without even the implied warranty of > 8 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > 9 ; GNU General Public License for more details. > 10 > 11 ; Scales the layer to match the selection size while maintaining > 12 ; original aspect ration. If no selection is present, scales > 13 ; layer to image size. Note: if the layer is floated (for example, > 14 ; after an Edit->Paste has been performed) there is no selection > 15 ; present even though there are marching ants around the originally > 16 ; selected region -- if this script is run without first making > 17 ; a new selection then the floating selection will be scaled to > 18 ; the image size. > 19 > 20 (define (script-fu-sg-layer-fit-in-selection image drawable) > 21 (let* ( > 22 (layer (car (gimp-image-get-active-layer image))) > 23 (bounds (cdr (gimp-selection-bounds image))) > 24 (x (car bounds)) > 25 (y (cadr bounds)) > 26 (width (- (caddr bounds) x)) > 27 (height (- (cadddr bounds) y)) > 28 (layer-width (car (gimp-drawable-width layer))) > 29 (layer-height (car (gimp-drawable-height layer))) > 30 (aspect (/ layer-height layer-width)) > 31 ) > 32 (gimp-image-undo-group-start image) > 33 (gimp-layer-add-alpha layer) > 34 (if (< (/ width layer-width) (/ height layer-height)) > 35 (begin > 36 (gimp-layer-scale-full layer > 37 width > 38 (* width aspect) > 39 TRUE > 40 INTERPOLATION-LANCZOS) > 41 (gimp-layer-set-offsets layer x (+ y (/ (- height (* width aspect)) 2) ) > 42 ) > 43 (begin > 44 (gimp-layer-scale-full layer > 45 (/ height aspect) > 46 height > 47 TRUE > 48 INTERPOLATION-LANCZOS) > 49 (gimp-layer-set-offsets layer (+ x (/ (- width (/ height aspect)) 2)) y) > 50 ) > 51 ) > 52 (gimp-image-undo-group-end image) > 53 (gimp-displays-flush) > 54 ) > 55 ) > 56 > 57 (script-fu-register "script-fu-sg-layer-fit-in-selection" > 58 "Fit within Selection" > 59 "Scale the active layer so it fits in the selected region" > 60 "Saul Goode" > 61 "Saul Goode" > 62 "10/25/2010" > 63 "RGB*,GRAY*" > 64 SF-IMAGE "Image" 0 > 65 SF-DRAWABLE "Drawable" 0 > 66 ) > 67 > 68 (script-fu-menu-register "script-fu-sg-layer-fit-in-selection" > 69 "<Image>/Layer/Resize" > 70 ) > 71