home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_gimp.idb / usr / freeware / share / gimp / scripts / slide.scm.z / slide.scm
Encoding:
GIMP Script-Fu Script  |  1999-07-21  |  6.6 KB  |  256 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ; This program is free software; you can redistribute it and/or modify
  4. ; it under the terms of the GNU General Public License as published by
  5. ; the Free Software Foundation; either version 2 of the License, or
  6. ; (at your option) any later version.
  7. ; This program is distributed in the hope that it will be useful,
  8. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10. ; GNU General Public License for more details.
  11. ; You should have received a copy of the GNU General Public License
  12. ; along with this program; if not, write to the Free Software
  13. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. ;
  15. ;
  16. ; slide.scm   version 0.30   12/13/97
  17. ;
  18. ; CHANGE-LOG:
  19. ; 0.20 - first public release
  20. ; 0.30 - some code cleanup
  21. ;        now uses the rotate plug-in to improve speed
  22. ;
  23. ; !still in development!
  24. ; TODO: - change the script so that the film is rotated, not the image
  25. ;       - antialiasing
  26. ;       - make 'add background' an option
  27. ;       - ?
  28. ;
  29. ; Copyright (C) 1997 Sven Neumann (neumanns@uni-duesseldorf.de) 
  30. ;  
  31. ; makes your picture look like a slide
  32. ;
  33. ; The script works on RGB and grayscale images that contain only 
  34. ; one layer. The image is cropped to fit into an aspect ratio of 1:1,5.
  35. ; It creates a copy of the image or can optionally work on the original. 
  36. ; The script uses the current background color to create a background 
  37. ; layer.
  38.  
  39.  
  40. (define (crop width height ratio)
  41.   (cond ((>= width (* ratio height)) (* ratio height))
  42.     ((< width (* ratio height))   width)))
  43.  
  44.  
  45. (define (script-fu-slide img 
  46.              drawable
  47.              text
  48.              number
  49.              font-family
  50.              font-color
  51.              work-on-copy)
  52.   (let* ((type (car (gimp-drawable-type-with-alpha drawable)))
  53.      (image (cond ((= work-on-copy TRUE) 
  54.                (car (gimp-channel-ops-duplicate img)))
  55.               ((= work-on-copy FALSE) 
  56.                img)))
  57.      (owidth (car (gimp-image-width image)))
  58.      (oheight (car (gimp-image-height image)))
  59.      (ratio (if (>= owidth oheight) (/ 3 2) 
  60.                                 (/ 2 3)))
  61.      (crop-width (crop owidth oheight ratio)) 
  62.      (crop-height (/ crop-width ratio))
  63.      (width (* (max crop-width crop-height) 1.05))
  64.      (height (* (min crop-width crop-height) 1.5))
  65.      (hole-width (/ width 20))
  66.      (hole-space (/ width 8))
  67.      (hole-height (/ width 12))
  68.      (hole-radius (/ hole-width 4))
  69.      (hole-start (- (/ (rand 1000) 1000) 0.5))
  70.      (old-bg (car (gimp-palette-get-background)))
  71.      (old-fg (car (gimp-palette-get-foreground)))
  72.      (film-layer (car (gimp-layer-new image 
  73.                       width 
  74.                       height 
  75.                       type 
  76.                       "Film" 
  77.                       100 
  78.                       NORMAL)))
  79.      (bg-layer (car (gimp-layer-new image 
  80.                     width 
  81.                     height 
  82.                     type 
  83.                     "Background" 
  84.                     100 
  85.                     NORMAL)))
  86.      (pic-layer (car (gimp-image-active-drawable image)))
  87.      (numbera (string-append number "A")))
  88.  
  89.  
  90.   (gimp-image-disable-undo image)
  91.  
  92. ; add an alpha channel to the image
  93.   (gimp-layer-add-alpha pic-layer)
  94.  
  95. ; crop, resize and eventually rotate the image 
  96.   (gimp-crop image 
  97.          crop-width 
  98.          crop-height 
  99.          (/ (- owidth crop-width) 2)
  100.          (/ (- oheight crop-height) 2))
  101.   (gimp-image-resize image 
  102.              width 
  103.              height 
  104.              (/ (- width crop-width) 2)
  105.              (/ (- height crop-height) 2))
  106.   (if (< ratio 1) (plug-in-rotate 1
  107.                   image 
  108.                   pic-layer
  109.                   1
  110.                   FALSE)) 
  111.  
  112. ; add the background layer
  113.   (gimp-drawable-fill bg-layer BG-IMAGE-FILL)
  114.   (gimp-image-add-layer image bg-layer -1)
  115.  
  116. ; add the film layer
  117.   (gimp-palette-set-background '(0 0 0))
  118.   (gimp-drawable-fill film-layer BG-IMAGE-FILL)
  119.  
  120. ; add the text
  121.   (gimp-palette-set-foreground font-color)
  122.   (gimp-floating-sel-anchor (car (gimp-text image
  123.                         film-layer
  124.                         (+ hole-start (* -0.25 width))
  125.                         (* 0.01 height)
  126.                         text
  127.                         0
  128.                         TRUE
  129.                         (* 0.040 height) PIXELS
  130.                         "*" font-family "*" "*" "*" "*" )))
  131.   (gimp-floating-sel-anchor (car (gimp-text image
  132.                         film-layer
  133.                         (+ hole-start (* 0.75 width))
  134.                         (* 0.01 height)
  135.                         text
  136.                         0
  137.                         TRUE
  138.                         (* 0.040 height) PIXELS
  139.                         "*" font-family "*" "*" "*" "*" )))
  140.   (gimp-floating-sel-anchor (car (gimp-text image
  141.                         film-layer          
  142.                         (+ hole-start (* 0.35 width))
  143.                         (* 0.01 height)
  144.                         number
  145.                         0
  146.                         TRUE
  147.                         (* 0.050 height) PIXELS
  148.                         "*" font-family "*" "*" "*" "*" )))
  149.   (gimp-floating-sel-anchor (car (gimp-text image
  150.                         film-layer          
  151.                         (+ hole-start (* 0.35 width))
  152.                         (* 0.95 height)
  153.                         number
  154.                         0
  155.                         TRUE
  156.                         (* 0.050 height) PIXELS
  157.                         "*" font-family "*" "*" "*" "*" )))
  158.   (gimp-floating-sel-anchor (car (gimp-text image
  159.                           film-layer          
  160.                           (+ hole-start (* 0.85 width))
  161.                           (* 0.95 height)
  162.                           numbera
  163.                           0
  164.                           TRUE
  165.                           (* 0.045 height) PIXELS
  166.                           "*" font-family "*" "*" "*" "*" )))
  167.  
  168. ; create a mask for the holes and cut them out
  169.   (let* ((film-mask (car (gimp-layer-create-mask film-layer WHITE-MASK)))
  170.      (hole hole-start)
  171.      (top-y (* height 0.06))
  172.      (bottom-y(* height 0.855))) 
  173.     (gimp-selection-none image)
  174.     (while (< hole 8)
  175.        (gimp-rect-select image 
  176.                  (* hole-space hole)
  177.                  top-y
  178.                  hole-width
  179.                  hole-height
  180.                  ADD
  181.                  FALSE
  182.                  0)     
  183.        (gimp-rect-select image 
  184.                  (* hole-space hole)
  185.                  bottom-y
  186.                  hole-width
  187.                  hole-height
  188.                  ADD
  189.                  FALSE
  190.                  0)
  191.        (set! hole (+ hole 1)))
  192.  
  193.     (gimp-palette-set-foreground '(0 0 0))
  194.     (gimp-edit-fill image film-mask)
  195.     (gimp-selection-none image)
  196.     (plug-in-gauss-rle 1 image film-mask hole-radius TRUE TRUE)
  197.     (gimp-threshold image film-mask 127 255)
  198.  
  199.     (gimp-image-add-layer image film-layer -1)
  200.     (gimp-image-add-layer-mask image film-layer film-mask))
  201.  
  202. ; reorder the layers
  203.   (gimp-image-raise-layer image pic-layer)
  204.   (gimp-image-raise-layer image pic-layer)
  205.  
  206. ; clean up after the script
  207.   (gimp-selection-none image)
  208.   (gimp-palette-set-background old-bg)
  209.   (gimp-palette-set-foreground old-fg)
  210.   (gimp-image-enable-undo image)
  211.   (if (= work-on-copy TRUE) (gimp-display-new image))
  212.   (gimp-displays-flush)))
  213.  
  214. (script-fu-register "script-fu-slide" 
  215.             "<Image>/Script-Fu/Decor/Slide"
  216.             "Gives the image the look of a slide"
  217.             "Sven Neumann (neumanns@uni-duesseldorf.de)"
  218.             "Sven Neumann"
  219.             "12/13/1997"
  220.             "RGB GRAY"
  221.             SF-IMAGE "Image" 0
  222.             SF-DRAWABLE "Drawable" 0
  223.             SF-VALUE "Text" "\"The GIMP\""
  224.             SF-VALUE "Number" "\"32\""
  225.             SF-VALUE "Font" "\"Utopia\""
  226.             SF-COLOR "Font Color" '(255 180 0)
  227.             SF-TOGGLE "Work on copy" TRUE) 
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.