GIMP Script-fu

Hex Artifact Content
Login

Artifact b3125523d67c5b30662f7e7a645554f8d92005a3:


0000: 3b 20 54 68 69 73 20 70 72 6f 67 72 61 6d 20 69  ; This program i
0010: 73 20 66 72 65 65 20 73 6f 66 74 77 61 72 65 3b  s free software;
0020: 20 79 6f 75 20 63 61 6e 20 72 65 64 69 73 74 72   you can redistr
0030: 69 62 75 74 65 20 69 74 20 61 6e 64 2f 6f 72 20  ibute it and/or 
0040: 6d 6f 64 69 66 79 0a 3b 20 69 74 20 75 6e 64 65  modify.; it unde
0050: 72 20 74 68 65 20 74 65 72 6d 73 20 6f 66 20 74  r the terms of t
0060: 68 65 20 47 4e 55 20 47 65 6e 65 72 61 6c 20 50  he GNU General P
0070: 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 20 61 73  ublic License as
0080: 20 70 75 62 6c 69 73 68 65 64 20 62 79 0a 3b 20   published by.; 
0090: 74 68 65 20 46 72 65 65 20 53 6f 66 74 77 61 72  the Free Softwar
00a0: 65 20 46 6f 75 6e 64 61 74 69 6f 6e 3b 20 65 69  e Foundation; ei
00b0: 74 68 65 72 20 76 65 72 73 69 6f 6e 20 32 20 6f  ther version 2 o
00c0: 66 20 74 68 65 20 4c 69 63 65 6e 73 65 2c 20 6f  f the License, o
00d0: 72 0a 3b 20 28 61 74 20 79 6f 75 72 20 6f 70 74  r.; (at your opt
00e0: 69 6f 6e 29 20 61 6e 79 20 6c 61 74 65 72 20 76  ion) any later v
00f0: 65 72 73 69 6f 6e 2e 0a 3b 0a 3b 20 54 68 69 73  ersion..;.; This
0100: 20 70 72 6f 67 72 61 6d 20 69 73 20 64 69 73 74   program is dist
0110: 72 69 62 75 74 65 64 20 69 6e 20 74 68 65 20 68  ributed in the h
0120: 6f 70 65 20 74 68 61 74 20 69 74 20 77 69 6c 6c  ope that it will
0130: 20 62 65 20 75 73 65 66 75 6c 2c 0a 3b 20 62 75   be useful,.; bu
0140: 74 20 57 49 54 48 4f 55 54 20 41 4e 59 20 57 41  t WITHOUT ANY WA
0150: 52 52 41 4e 54 59 3b 20 77 69 74 68 6f 75 74 20  RRANTY; without 
0160: 65 76 65 6e 20 74 68 65 20 69 6d 70 6c 69 65 64  even the implied
0170: 20 77 61 72 72 61 6e 74 79 20 6f 66 0a 3b 20 4d   warranty of.; M
0180: 45 52 43 48 41 4e 54 41 42 49 4c 49 54 59 20 6f  ERCHANTABILITY o
0190: 72 20 46 49 54 4e 45 53 53 20 46 4f 52 20 41 20  r FITNESS FOR A 
01a0: 50 41 52 54 49 43 55 4c 41 52 20 50 55 52 50 4f  PARTICULAR PURPO
01b0: 53 45 2e 20 20 53 65 65 20 74 68 65 0a 3b 20 47  SE.  See the.; G
01c0: 4e 55 20 47 65 6e 65 72 61 6c 20 50 75 62 6c 69  NU General Publi
01d0: 63 20 4c 69 63 65 6e 73 65 20 66 6f 72 20 6d 6f  c License for mo
01e0: 72 65 20 64 65 74 61 69 6c 73 2e 0a 0a 3b 20 53  re details...; S
01f0: 63 61 6c 65 73 20 74 68 65 20 6c 61 79 65 72 20  cales the layer 
0200: 74 6f 20 6d 61 74 63 68 20 74 68 65 20 73 65 6c  to match the sel
0210: 65 63 74 69 6f 6e 20 73 69 7a 65 2e 0a 3b 20 49  ection size..; I
0220: 66 20 6e 6f 20 73 65 6c 65 63 74 69 6f 6e 20 69  f no selection i
0230: 73 20 70 72 65 73 65 6e 74 2c 20 73 63 61 6c 65  s present, scale
0240: 73 20 6c 61 79 65 72 20 74 6f 20 69 6d 61 67 65  s layer to image
0250: 20 73 69 7a 65 20 0a 3b 20 4e 6f 74 65 3a 20 69   size .; Note: i
0260: 66 20 74 68 65 20 6c 61 79 65 72 20 69 73 20 66  f the layer is f
0270: 6c 6f 61 74 65 64 20 74 68 65 72 65 20 69 73 20  loated there is 
0280: 6e 6f 20 73 65 6c 65 63 74 69 6f 6e 20 70 72 65  no selection pre
0290: 73 65 6e 74 0a 3b 20 65 76 65 6e 20 74 68 6f 75  sent.; even thou
02a0: 67 68 20 74 68 65 72 65 20 61 72 65 20 6d 61 72  gh there are mar
02b0: 63 68 69 6e 67 20 61 6e 74 73 20 61 72 6f 75 6e  ching ants aroun
02c0: 64 20 74 68 65 20 6f 72 69 67 69 6e 61 6c 6c 79  d the originally
02d0: 0a 3b 20 73 65 6c 65 63 74 65 64 20 72 65 67 69  .; selected regi
02e0: 6f 6e 20 2d 2d 20 69 66 20 74 68 69 73 20 73 63  on -- if this sc
02f0: 72 69 70 74 20 69 73 20 72 75 6e 20 77 69 74 68  ript is run with
0300: 6f 75 74 20 66 69 72 73 74 20 6d 61 6b 69 6e 67  out first making
0310: 0a 3b 20 61 20 6e 65 77 20 73 65 6c 65 63 74 69  .; a new selecti
0320: 6f 6e 20 74 68 65 6e 20 74 68 65 20 66 6c 6f 61  on then the floa
0330: 74 69 6e 67 20 73 65 6c 65 63 74 69 6f 6e 20 77  ting selection w
0340: 69 6c 6c 20 62 65 20 73 63 61 6c 65 64 20 74 6f  ill be scaled to
0350: 0a 3b 20 74 68 65 20 69 6d 61 67 65 20 73 69 7a  .; the image siz
0360: 65 2e 20 0a 0a 28 64 65 66 69 6e 65 20 28 73 67  e. ..(define (sg
0370: 2d 6c 61 79 65 72 2d 73 63 61 6c 65 2d 74 6f 2d  -layer-scale-to-
0380: 73 65 6c 65 63 74 69 6f 6e 20 69 6d 61 67 65 20  selection image 
0390: 64 72 61 77 61 62 6c 65 29 0a 20 20 28 6c 65 74  drawable).  (let
03a0: 2a 20 28 0a 20 20 20 20 20 20 28 6c 61 79 65 72  * (.      (layer
03b0: 20 28 63 61 72 20 28 67 69 6d 70 2d 69 6d 61 67   (car (gimp-imag
03c0: 65 2d 67 65 74 2d 61 63 74 69 76 65 2d 6c 61 79  e-get-active-lay
03d0: 65 72 20 69 6d 61 67 65 29 29 29 0a 20 20 20 20  er image))).    
03e0: 20 20 28 62 6f 75 6e 64 73 20 28 67 69 6d 70 2d    (bounds (gimp-
03f0: 73 65 6c 65 63 74 69 6f 6e 2d 62 6f 75 6e 64 73  selection-bounds
0400: 20 69 6d 61 67 65 29 29 0a 20 20 20 20 20 20 28   image)).      (
0410: 78 20 30 29 0a 20 20 20 20 20 20 28 79 20 30 29  x 0).      (y 0)
0420: 0a 20 20 20 20 20 20 28 77 69 64 74 68 20 28 63  .      (width (c
0430: 61 72 20 28 67 69 6d 70 2d 69 6d 61 67 65 2d 77  ar (gimp-image-w
0440: 69 64 74 68 20 69 6d 61 67 65 29 29 29 0a 20 20  idth image))).  
0450: 20 20 20 20 28 68 65 69 67 68 74 20 28 63 61 72      (height (car
0460: 20 28 67 69 6d 70 2d 69 6d 61 67 65 2d 68 65 69   (gimp-image-hei
0470: 67 68 74 20 69 6d 61 67 65 29 29 29 0a 20 20 20  ght image))).   
0480: 20 20 20 29 0a 20 20 20 20 28 77 68 65 6e 20 28     ).    (when (
0490: 3d 20 28 63 61 72 20 62 6f 75 6e 64 73 29 20 54  = (car bounds) T
04a0: 52 55 45 29 0a 20 20 20 20 20 20 28 73 65 74 21  RUE).      (set!
04b0: 20 78 20 28 63 61 64 72 20 62 6f 75 6e 64 73 29   x (cadr bounds)
04c0: 29 0a 20 20 20 20 20 20 28 73 65 74 21 20 79 20  ).      (set! y 
04d0: 28 63 61 64 64 72 20 62 6f 75 6e 64 73 29 29 0a  (caddr bounds)).
04e0: 20 20 20 20 20 20 28 73 65 74 21 20 77 69 64 74        (set! widt
04f0: 68 20 28 2d 20 28 63 61 64 64 64 72 20 62 6f 75  h (- (cadddr bou
0500: 6e 64 73 29 20 78 29 29 0a 20 20 20 20 20 20 28  nds) x)).      (
0510: 73 65 74 21 20 68 65 69 67 68 74 20 28 2d 20 28  set! height (- (
0520: 63 61 72 20 28 63 64 64 64 64 72 20 62 6f 75 6e  car (cddddr boun
0530: 64 73 29 29 20 79 29 29 29 0a 20 20 20 20 28 67  ds)) y))).    (g
0540: 69 6d 70 2d 69 6d 61 67 65 2d 75 6e 64 6f 2d 67  imp-image-undo-g
0550: 72 6f 75 70 2d 73 74 61 72 74 20 69 6d 61 67 65  roup-start image
0560: 29 0a 20 20 20 20 28 67 69 6d 70 2d 6c 61 79 65  ).    (gimp-laye
0570: 72 2d 73 63 61 6c 65 20 6c 61 79 65 72 20 77 69  r-scale layer wi
0580: 64 74 68 20 68 65 69 67 68 74 20 54 52 55 45 29  dth height TRUE)
0590: 0a 20 20 20 20 28 67 69 6d 70 2d 6c 61 79 65 72  .    (gimp-layer
05a0: 2d 73 65 74 2d 6f 66 66 73 65 74 73 20 6c 61 79  -set-offsets lay
05b0: 65 72 20 78 20 79 29 0a 20 20 20 20 28 67 69 6d  er x y).    (gim
05c0: 70 2d 69 6d 61 67 65 2d 75 6e 64 6f 2d 67 72 6f  p-image-undo-gro
05d0: 75 70 2d 65 6e 64 20 69 6d 61 67 65 29 0a 20 20  up-end image).  
05e0: 20 20 28 67 69 6d 70 2d 64 69 73 70 6c 61 79 73    (gimp-displays
05f0: 2d 66 6c 75 73 68 29 0a 20 20 20 20 29 0a 20 20  -flush).    ).  
0600: 29 0a 0a 28 73 63 72 69 70 74 2d 66 75 2d 72 65  )..(script-fu-re
0610: 67 69 73 74 65 72 20 22 73 67 2d 6c 61 79 65 72  gister "sg-layer
0620: 2d 73 63 61 6c 65 2d 74 6f 2d 73 65 6c 65 63 74  -scale-to-select
0630: 69 6f 6e 22 0a 20 22 53 63 61 6c 65 20 74 6f 20  ion". "Scale to 
0640: 53 65 6c 65 63 74 69 6f 6e 22 0a 20 22 53 63 61  Selection". "Sca
0650: 6c 65 20 74 68 65 20 61 63 74 69 76 65 20 6c 61  le the active la
0660: 79 65 72 20 61 6e 64 20 66 69 74 20 69 74 20 69  yer and fit it i
0670: 6e 20 74 68 65 20 73 65 6c 65 63 74 69 6f 6e 20  n the selection 
0680: 28 72 65 63 74 61 6e 67 75 6c 61 72 29 22 0a 20  (rectangular)". 
0690: 22 53 61 75 6c 20 47 6f 6f 64 65 22 0a 20 22 53  "Saul Goode". "S
06a0: 61 75 6c 20 47 6f 6f 64 65 22 0a 20 22 31 2f 33  aul Goode". "1/3
06b0: 2f 32 30 31 30 22 0a 20 22 2a 22 0a 20 53 46 2d  /2010". "*". SF-
06c0: 49 4d 41 47 45 20 20 20 20 22 49 6d 61 67 65 22  IMAGE    "Image"
06d0: 20 20 20 20 30 0a 20 53 46 2d 44 52 41 57 41 42      0. SF-DRAWAB
06e0: 4c 45 20 22 44 72 61 77 61 62 6c 65 22 20 30 0a  LE "Drawable" 0.
06f0: 20 29 0a 28 73 63 72 69 70 74 2d 66 75 2d 6d 65   ).(script-fu-me
0700: 6e 75 2d 72 65 67 69 73 74 65 72 20 22 73 67 2d  nu-register "sg-
0710: 6c 61 79 65 72 2d 73 63 61 6c 65 2d 74 6f 2d 73  layer-scale-to-s
0720: 65 6c 65 63 74 69 6f 6e 22 0a 20 22 3c 49 6d 61  election". "<Ima
0730: 67 65 3e 2f 4c 61 79 65 72 2f 52 65 73 69 7a 65  ge>/Layer/Resize
0740: 22 0a 20 29 0a 20 0a                             ". ). .