~ubuntu-branches/ubuntu/maverick/gimp/maverick-updates

« back to all changes in this revision

Viewing changes to plug-ins/script-fu/scripts/slide.scm

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2005-12-09 19:44:52 UTC
  • Revision ID: james.westby@ubuntu.com-20051209194452-yggpemjlofpjqyf4
Tags: upstream-2.2.9
ImportĀ upstreamĀ versionĀ 2.2.9

Show diffs side-by-side

added added

removed removed

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