home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 August / ENTER.ISO / files / gimp-2.0.5-i586-setup.exe / {app} / share / gimp / 2.0 / scripts / slide.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2004-09-26  |  6.9 KB  |  243 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.41   2004/03/28
  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. ; 0.40 - changes to work with gimp-1.1 
  23. ;        if the image was rotated, rotate the whole thing back when finished
  24. ; 0.41 - changes to work with gimp-2.0, slightly correct text offsets,
  25. ;        Nils Philippsen <nphilipp@redhat.com> 2004/03/28
  26. ;
  27. ; !still in development!
  28. ; TODO: - change the script so that the film is rotated, not the image
  29. ;       - antialiasing
  30. ;       - make 'add background' an option
  31. ;       - ?
  32. ;
  33. ; Copyright (C) 1997-1999 Sven Neumann <sven@gimp.org>
  34. ;  
  35. ; makes your picture look like a slide
  36. ;
  37. ; The script works on RGB and grayscale images that contain only 
  38. ; one layer. The image is cropped to fit into an aspect ratio of 1:1,5.
  39. ; It creates a copy of the image or can optionally work on the original. 
  40. ; The script uses the current background color to create a background 
  41. ; layer.
  42.  
  43.  
  44. (define (crop width height ratio)
  45.   (cond ((>= width (* ratio height)) (* ratio height))
  46.     ((< width (* ratio height))   width)))
  47.  
  48.  
  49. (define (script-fu-slide img
  50.              drawable
  51.              text
  52.              number
  53.              fontname
  54.              font-color
  55.              work-on-copy)
  56.   (let* ((type (car (gimp-drawable-type-with-alpha drawable)))
  57.      (image (cond ((= work-on-copy TRUE)
  58.                (car (gimp-image-duplicate img)))
  59.               ((= work-on-copy FALSE)
  60.                img)))
  61.      (owidth (car (gimp-image-width image)))
  62.      (oheight (car (gimp-image-height image)))
  63.      (ratio (if (>= owidth oheight) (/ 3 2)
  64.                                 (/ 2 3)))
  65.      (crop-width (crop owidth oheight ratio))
  66.      (crop-height (/ crop-width ratio))
  67.      (width (* (max crop-width crop-height) 1.05))
  68.      (height (* (min crop-width crop-height) 1.5))
  69.      (hole-width (/ width 20))
  70.      (hole-space (/ width 8))
  71.      (hole-height (/ width 12))
  72.      (hole-radius (/ hole-width 4))
  73.      (hole-start (- (/ (rand 1000) 1000) 0.5))
  74.      (old-bg (car (gimp-palette-get-background)))
  75.      (old-fg (car (gimp-palette-get-foreground)))
  76.      (film-layer (car (gimp-layer-new image
  77.                       width
  78.                       height
  79.                       type
  80.                       "Film"
  81.                       100
  82.                       NORMAL-MODE)))
  83.      (bg-layer (car (gimp-layer-new image
  84.                     width
  85.                     height
  86.                     type
  87.                     "Background"
  88.                     100
  89.                     NORMAL-MODE)))
  90.      (pic-layer (car (gimp-image-get-active-drawable image)))
  91.      (numbera (string-append number "A")))
  92.  
  93.  
  94.   (gimp-image-undo-disable image)
  95.  
  96. ; add an alpha channel to the image
  97.   (gimp-layer-add-alpha pic-layer)
  98.  
  99. ; crop, resize and eventually rotate the image 
  100.   (gimp-image-crop image
  101.            crop-width
  102.            crop-height
  103.            (/ (- owidth crop-width) 2)
  104.            (/ (- oheight crop-height) 2))
  105.   (gimp-image-resize image
  106.              width
  107.              height
  108.              (/ (- width crop-width) 2)
  109.              (/ (- height crop-height) 2))
  110.   (if (< ratio 1) (plug-in-rotate 1
  111.                   image
  112.                   pic-layer
  113.                   1
  114.                   FALSE))
  115.  
  116. ; add the background layer
  117.   (gimp-drawable-fill bg-layer BACKGROUND-FILL)
  118.   (gimp-image-add-layer image bg-layer -1)
  119.  
  120. ; add the film layer
  121.   (gimp-palette-set-background '(0 0 0))
  122.   (gimp-drawable-fill film-layer BACKGROUND-FILL)
  123.   (gimp-image-add-layer image film-layer -1)
  124.  
  125. ; add the text
  126.   (gimp-palette-set-foreground font-color)
  127.   (gimp-floating-sel-anchor (car (gimp-text-fontname image
  128.                         film-layer
  129.                         (+ hole-start (* -0.25 width))
  130.                         (* 0.01 height)
  131.                         text
  132.                         0
  133.                         TRUE
  134.                         (* 0.040 height) PIXELS fontname)))
  135.   (gimp-floating-sel-anchor (car (gimp-text-fontname image
  136.                         film-layer
  137.                         (+ hole-start (* 0.75 width))
  138.                         (* 0.01 height)
  139.                         text
  140.                         0
  141.                         TRUE
  142.                         (* 0.040 height) PIXELS
  143.                         fontname )))
  144.   (gimp-floating-sel-anchor (car (gimp-text-fontname image
  145.                         film-layer
  146.                         (+ hole-start (* 0.35 width))
  147.                         0.0
  148.                         number
  149.                         0
  150.                         TRUE
  151.                         (* 0.050 height) PIXELS
  152.                         fontname )))
  153.   (gimp-floating-sel-anchor (car (gimp-text-fontname image
  154.                         film-layer
  155.                         (+ hole-start (* 0.35 width))
  156.                         (* 0.94 height)
  157.                         number
  158.                         0
  159.                         TRUE
  160.                         (* 0.050 height) PIXELS
  161.                         fontname )))
  162.   (gimp-floating-sel-anchor (car (gimp-text-fontname image
  163.                           film-layer
  164.                           (+ hole-start (* 0.85 width))
  165.                           (* 0.945 height)
  166.                           numbera
  167.                           0
  168.                           TRUE
  169.                           (* 0.045 height) PIXELS
  170.                           fontname )))
  171.  
  172. ; create a mask for the holes and cut them out
  173.   (let* ((film-mask (car (gimp-layer-create-mask film-layer ADD-WHITE-MASK)))
  174.      (hole hole-start)
  175.      (top-y (* height 0.06))
  176.      (bottom-y(* height 0.855)))
  177.     (gimp-selection-none image)
  178.     (while (< hole 8)
  179.        (gimp-rect-select image
  180.                  (* hole-space hole)
  181.                  top-y
  182.                  hole-width
  183.                  hole-height
  184.                  CHANNEL-OP-ADD
  185.                  FALSE
  186.                  0)
  187.        (gimp-rect-select image
  188.                  (* hole-space hole)
  189.                  bottom-y
  190.                  hole-width
  191.                  hole-height
  192.                  CHANNEL-OP-ADD
  193.                  FALSE
  194.                  0)
  195.        (set! hole (+ hole 1)))
  196.  
  197.     (gimp-palette-set-foreground '(0 0 0))
  198.     (gimp-edit-fill film-mask BACKGROUND-FILL)
  199.     (gimp-selection-none image)
  200.     (plug-in-gauss-rle 1 image film-mask hole-radius TRUE TRUE)
  201.     (gimp-threshold film-mask 127 255)
  202.  
  203.     (gimp-layer-add-mask film-layer film-mask)
  204.     (gimp-layer-remove-mask film-layer MASK-APPLY))
  205.  
  206. ; reorder the layers
  207.   (gimp-image-raise-layer image pic-layer)
  208.   (gimp-image-raise-layer image pic-layer)
  209.  
  210. ; eventually rotate the whole thing back
  211.   (if (< ratio 1) 
  212.       (plug-in-rotate 1
  213.               image
  214.               pic-layer
  215.               3
  216.               TRUE))
  217.  
  218. ; clean up after the script
  219.   (gimp-selection-none image)
  220.   (gimp-palette-set-background old-bg)
  221.   (gimp-palette-set-foreground old-fg)
  222.   (gimp-image-undo-enable image)
  223.   (if (= work-on-copy TRUE) (gimp-display-new image))
  224.   (gimp-displays-flush)))
  225.  
  226. (script-fu-register "script-fu-slide"
  227.             _"<Image>/Script-Fu/Decor/_Slide..."
  228.             "Gives the image the look of a slide"
  229.             "Sven Neumann <sven@gimp.org>"
  230.             "Sven Neumann"
  231.             "2004/03/28"
  232.             "RGB GRAY"
  233.             SF-IMAGE    "Image"          0
  234.             SF-DRAWABLE "Drawable"       0
  235.             SF-STRING   _"Text"          "The GIMP"
  236.             SF-STRING   _"Number"        "32"
  237.             SF-FONT     _"Font"          "Serif"
  238.             SF-COLOR    _"Font Color"    '(255 180 0)
  239.             SF-TOGGLE   _"Work on Copy"  TRUE)
  240.