[gimp] plug-ins: make "filename" accessible to the loop of "with-files" macro.



commit 4d23939c3dff241bd87e80b2e277e2742a7d7233
Author: Jehan <jehan girinstud io>
Date:   Mon May 30 19:20:50 2016 +0200

    plug-ins: make "filename" accessible to the loop of "with-files" macro.
    
    The filename of the current bash file being processed is a pretty useful
    data to access in a script.

 plug-ins/script-fu/scripts/script-fu-util.scm |   32 ++++++++++++++----------
 1 files changed, 19 insertions(+), 13 deletions(-)
---
diff --git a/plug-ins/script-fu/scripts/script-fu-util.scm b/plug-ins/script-fu/scripts/script-fu-util.scm
index 4f036b8..e9e7adf 100644
--- a/plug-ins/script-fu/scripts/script-fu-util.scm
+++ b/plug-ins/script-fu/scripts/script-fu-util.scm
@@ -49,20 +49,26 @@
 ;     gimp -i -b '(with-files "*.png" <body>)'
 ;
 ; where <body> is the code that handles whatever processing you want to
-; perform on the files. There are three variables that are available within
-; the <body>: 'basename', 'image', and 'layer'. The 'basename' is the
-; name of the file with its extension removed, while the other two
-; variables are self-explanatory. You basically write your code as though
-; it were processing a single 'image' and the 'with-files' macro applies
-; it to all of the files matching the pattern.
+; perform on the files. There are four variables that are available
+; within the <body>: 'basename', 'image', 'filename' and 'layer'.
+; The 'basename' is the name of the file with its extension removed,
+; while the other three variables are self-explanatory.
+; You basically write your code as though it were processing a single
+; 'image' and the 'with-files' macro applies it to all of the files
+; matching the pattern.
 ;
 ; For example, to invert the colors of all of the PNG files in the
 ; start directory:
 ;
 ;    gimp -i -b '(with-files "*.png" (gimp-invert layer) \
-;                  (gimp-file-save 1 image layer \
-;                                  (string-append basename ".png") \
-;                                  (string-append basename ".png") ))'
+;                 (gimp-file-save 1 image layer filename filename ))'
+;
+; To do the same thing, but saving them as jpeg instead:
+;
+;    gimp -i -b '(with-files "*.png" (gimp-invert layer) \
+;                 (gimp-file-save 1 image layer \
+;                  (string-append basename ".jpg") \
+;                  (string-append basename ".jpg") ))'
 
 (define-macro (with-files pattern . body)
   (let ((loop (gensym))
@@ -71,12 +77,12 @@
     `(begin
        (let ,loop ((,filenames (cadr (file-glob ,pattern 1))))
          (unless (null? ,filenames)
-           (let* ((,filename (car ,filenames))
+           (let* ((filename (car ,filenames))
                   (image (catch #f (car (gimp-file-load RUN-NONINTERACTIVE
-                                                        ,filename
-                                                        ,filename ))))
+                                                        filename
+                                                        filename ))))
                   (layer (if image (car (gimp-image-get-active-layer image)) #f))
-                  (basename (unbreakupstr (butlast (strbreakup ,filename ".")) ".")))
+                  (basename (unbreakupstr (butlast (strbreakup filename ".")) ".")))
              (when image
                ,@body
                (gimp-image-delete image)))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]