[gimp] Simplify command line processing by adding a 'with-files' macro.
- From: Jehan Pagès <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] Simplify command line processing by adding a 'with-files' macro.
- Date: Mon, 30 May 2016 17:37:36 +0000 (UTC)
commit b6611b94ad036b25fad7f5aaa10778d8056aa55d
Author: saul <saul crazyauntgail com>
Date: Sun Mar 23 20:36:06 2014 -0400
Simplify command line processing by adding a 'with-files' macro.
plug-ins/script-fu/scripts/script-fu-util.scm | 38 +++++++++++++++++++++++++
1 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/plug-ins/script-fu/scripts/script-fu-util.scm b/plug-ins/script-fu/scripts/script-fu-util.scm
index 546b1ed..09af751 100644
--- a/plug-ins/script-fu/scripts/script-fu-util.scm
+++ b/plug-ins/script-fu/scripts/script-fu-util.scm
@@ -44,3 +44,41 @@
)
)
+; Allow command line usage of GIMP such as:
+;
+; 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.
+;
+; 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") ))'
+
+(define-macro (with-files pattern . body)
+ (let ((loop (gensym))
+ (filenames (gensym))
+ (filename (gensym)))
+ `(begin
+ (let ,loop ((,filenames (cadr (file-glob ,pattern 1))))
+ (unless (null? ,filenames)
+ (let* ((,filename (car ,filenames))
+ (image (catch #f (car (gimp-file-load RUN-NONINTERACTIVE
+ ,filename
+ ,filename ))))
+ (layer (if image (car (gimp-image-get-active-layer image)) #f))
+ (basename (unbreakupstr (butlast (strbreakup ,filename ".")) ".")))
+ (when image
+ ,@body
+ (gimp-image-delete image)))
+ (,loop (cdr ,filenames))))
+ (gimp-quit 0))))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]