GIMP Script-fu

Check-in [db8f2ac5bf]
Login

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

Overview
Comment:Added a new mode to get-layers which includes fundaments for nested groups.
Timelines: family | ancestors | trunk
Files: files | file ages | folders
SHA1:db8f2ac5bfcab174f2ea9cdccf823c9147087855
User & Date: saul 2015-07-09 12:03:20
Context
2015-07-09
12:03
Added a new mode to get-layers which includes fundaments for nested groups. Leaf check-in: db8f2ac5bf user: saul tags: trunk
2015-05-26
06:40
Updated docs. Leaf check-in: 1d3eeebbcb user: saul tags: schemey-fu
2015-05-22
21:34
Float layer added to useful functions. check-in: 260a9faba6 user: saul tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to doc/schemey-fu-manual.txt.

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
...
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
...
169
170
171
172
173
174
175
176






177
178
179
180
181
182
183

    (Vectors::stroke-new-from-points path 
                                     VECTORS-STROKE-TYPE-BEZIER  
                                     '(34 5 40 10 42 15 54 15 41 20 68 24)
                                     1)
      ==> stroke-id
      
Note that this transformation of counted arrays only applies to GIMP internal
procedures; plug-ins with counted array parameters (such as 'plug-in-film') need to be handled in the traditional manner. Fortunately, there are very few instances where this is a concern.

NAMESPACES

By now you've probably realized that Schemey-fu functions follow the naming convention of "Namespace::function", which consistly maps to the corresponding PDB procedure's name.

Within the PDB, procedures are divided up into different namespaces with the namespace supplied as a prefix in the procedure name. The main top-level namespaces are 'gimp', 'file', 'script-fu', and 'plug-in'. Schemey-fu is mostly limited to the procedures within the 'gimp' namespace. The 'gimp' namespace itself generally follows the naming convention of gimp-object-action, where the object might be an image, a layer, a tool, or somesuch.

................................................................................
        Reverse the order of the characters in a string.
    Fu::string-trim (str [pred])
        Per SRFI-13 without optional start/end.
        Skip over initial characters matching the 'pred'. 
        'pred' can be either a procedure or a char; if 
        not supplied, pred defaults to #\space.
    Fu::string-pad (str n [char])
       Per SRFI-13 without start/end (also does not truncate str).
       Prepends enough 'char's to string to fill field of size 'n'
       If not supplied, 'char' is #\space.
    Fu::string-delete (pred str)
        Per SRFI-13 without optional start/end.
        Remove all chars from a string that match 'pred'
        'pred' can be either a procedure or a char.

    Fu::progression (start end [num-elements [growth]])
        Return a list of N elements from start to end with either
................................................................................
        Merge sort a list based on compare? Optimal for longer lists (> 50 items)
        Example:
          (Fu::msort < '(30 20 50 40 10)) ==> (10 20 30 40 50)
          
    Fu::get-bounds (drawables)
        Accepts either the ID of a single drawable or a list of drawable IDs. 
        If a list then the bounds of all drawables in the list is returned.
    






    Fu::calc-fontsize (text font width height)
        Calculate the largest size of the given font that will fit within 
        the given dimensions.

USEFUL MACROS
   
   Schemey-fu also provides some useful macros. These do not follow the 







<
|







 







|
|
|







 







|
>
>
>
>
>
>







49
50
51
52
53
54
55

56
57
58
59
60
61
62
63
...
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
...
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188

    (Vectors::stroke-new-from-points path 
                                     VECTORS-STROKE-TYPE-BEZIER  
                                     '(34 5 40 10 42 15 54 15 41 20 68 24)
                                     1)
      ==> stroke-id
      

Note that this transformation of counted arrays only applies to GIMP internal procedures; plug-ins with counted array parameters (such as 'plug-in-film') need to be handled in the traditional manner. Fortunately, there are very few instances where this is a concern.

NAMESPACES

By now you've probably realized that Schemey-fu functions follow the naming convention of "Namespace::function", which consistly maps to the corresponding PDB procedure's name.

Within the PDB, procedures are divided up into different namespaces with the namespace supplied as a prefix in the procedure name. The main top-level namespaces are 'gimp', 'file', 'script-fu', and 'plug-in'. Schemey-fu is mostly limited to the procedures within the 'gimp' namespace. The 'gimp' namespace itself generally follows the naming convention of gimp-object-action, where the object might be an image, a layer, a tool, or somesuch.

................................................................................
        Reverse the order of the characters in a string.
    Fu::string-trim (str [pred])
        Per SRFI-13 without optional start/end.
        Skip over initial characters matching the 'pred'. 
        'pred' can be either a procedure or a char; if 
        not supplied, pred defaults to #\space.
    Fu::string-pad (str n [char])
        Per SRFI-13 without start/end (also does not truncate str).
        Prepends enough 'char's to string to fill field of size 'n'
        If not supplied, 'char' is #\space.
    Fu::string-delete (pred str)
        Per SRFI-13 without optional start/end.
        Remove all chars from a string that match 'pred'
        'pred' can be either a procedure or a char.

    Fu::progression (start end [num-elements [growth]])
        Return a list of N elements from start to end with either
................................................................................
        Merge sort a list based on compare? Optimal for longer lists (> 50 items)
        Example:
          (Fu::msort < '(30 20 50 40 10)) ==> (10 20 30 40 50)
          
    Fu::get-bounds (drawables)
        Accepts either the ID of a single drawable or a list of drawable IDs. 
        If a list then the bounds of all drawables in the list is returned.

    Fu::grow-while (pred? . args)
        Returns the largest integer that satisfies the 'pred?' function.
        The 'pred?' function should accept a single "size" argument
        and return #t if the size fits the criteria. (Se Fu::calc-fontsize
        for an example of usage.)

    Fu::calc-fontsize (text font width height)
        Calculate the largest size of the given font that will fit within 
        the given dimensions.

USEFUL MACROS
   
   Schemey-fu also provides some useful macros. These do not follow the 

Changes to schemey-fu.scm.

207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
...
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
    (pdb-pass  2 gimp-image-undo-group-end)
    (pdb-pass  2 gimp-image-undo-group-start)
    (pdb-bool  2 gimp-image-undo-is-enabled)
    (pdb-decar 2 gimp-image-undo-thaw)
    (pdb-pass  2 gimp-image-unset-active-channel)
    (pdb-decar 2 gimp-image-width)

    ; get-layers will return just the top-level layers and fundaments
    ; if 'mode' is either #f or omitted altogether (the latter for 
    ; compatibility with the PDB version)
    ; If 'mode' is #t then a nested list of all real layers (no
    ; fundaments) is returned.
    ;
    (define (get-layers image . mode)
      (let ((top-layers (vector->list (cadr (gimp-image-get-layers image)))))
        (if (or (null? mode) (not (car mode)))
          top-layers
          (let loop ((top-layers top-layers)
                     (layers '()))
            (if (null? top-layers)
              (reverse layers)
              (loop (cdr top-layers)
                    (cons (if (zero? (car (gimp-item-is-group (car top-layers))))
                            (car top-layers)
                            (Item::get-children (car top-layers) (car mode)))
                          layers)))))))

    ; Image::get-layers takes an option 'mode' argument (that is not
    ; available with the 'gimp-image-get-layers' procedure).
    ; if 'mode' is either 0 or omitted altogether return just the 
    ;   top-level layers and fundaments
    ; If 'mode' is 1 then a nested list of all real layers (no
    ;   fundaments) is returned.
    ; If 'mode' is 2 then a nested list is returned, where the first
................................................................................
            (if (null? top-layers)
              (reverse layers)
              (loop (cdr top-layers)
                    (cons (if (zero? (car (gimp-item-is-group (car top-layers))))
                            (car top-layers)
                            (if (= (car mode) 2)
                              (cons (car top-layers)
                                    (get-children (car top-layers) (car mode)))
                              (get-children (car top-layers) (car mode))))
                          layers)))))))
    (define (list)
      (vector->list (cadr (gimp-image-list))))
    ))
    
(define Layer
  (make-environment 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







|
|







207
208
209
210
211
212
213




















214
215
216
217
218
219
220
...
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
    (pdb-pass  2 gimp-image-undo-group-end)
    (pdb-pass  2 gimp-image-undo-group-start)
    (pdb-bool  2 gimp-image-undo-is-enabled)
    (pdb-decar 2 gimp-image-undo-thaw)
    (pdb-pass  2 gimp-image-unset-active-channel)
    (pdb-decar 2 gimp-image-width)





















    ; Image::get-layers takes an option 'mode' argument (that is not
    ; available with the 'gimp-image-get-layers' procedure).
    ; if 'mode' is either 0 or omitted altogether return just the 
    ;   top-level layers and fundaments
    ; If 'mode' is 1 then a nested list of all real layers (no
    ;   fundaments) is returned.
    ; If 'mode' is 2 then a nested list is returned, where the first
................................................................................
            (if (null? top-layers)
              (reverse layers)
              (loop (cdr top-layers)
                    (cons (if (zero? (car (gimp-item-is-group (car top-layers))))
                            (car top-layers)
                            (if (= (car mode) 2)
                              (cons (car top-layers)
                                    (Item::get-children (car top-layers) (car mode)))
                              (Item::get-children (car top-layers) (car mode))))
                          layers)))))))
    (define (list)
      (vector->list (cadr (gimp-image-list))))
    ))
    
(define Layer
  (make-environment