Skip to content

Commit bd71438

Browse files
Fix #94: compatibility with gimp v2 again
This adds a second version of the gimpscript file containing the script for gimp v2 (i.e. the version as it was before the previous commit). The makefile now checks the gimp version and selects which of the two script files to use based on that. It would be nicer if the script itself checked the gimp version and adapted accordingly, but it seems gimp v3 uses a newer scheme version and newer syntactical elements (i.e. "#:foo" symbols) that the version in gimp v2 does not understand, making this hard or impossible (at least for an inexperienced scheme programmer). This commit is intentionally separate from the previous commit (which adapts the script for v3 compatibility), so the diff for the previous commit is easier to read. This is the last part to fix #94.
1 parent 0b0e2e6 commit bd71438

2 files changed

Lines changed: 104 additions & 1 deletion

File tree

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ PYTHON ?= python3
100100
GIMP ?= $(shell command -v gimp-console)
101101
GIMP_FLAGS ?= -n -i --batch-interpreter=plug-in-script-fu-eval
102102

103+
ifneq ($(findstring GNU Image Manipulation Program version 2., $(shell $(GIMP) --version)),)
104+
GIMP_SCRIPT ?= $(SCRIPT_DIR)/gimpscript-v2
105+
else
106+
GIMP_SCRIPT ?= $(SCRIPT_DIR)/gimpscript
107+
endif
108+
103109
# NML
104110
NML ?= nmlc
105111
NML_FLAGS ?= -c
@@ -250,7 +256,7 @@ Makefile.gfx: $(GFX_SCRIPT_LIST_FILES) Makefile Makefile.config
250256
for i in `cat $$j | grep "\([pP][cCnN][xXgG]\)" | grep -v "^#" | cut -d\ -f1 | sed "s/\.\([pP][cCnN][xXgG]\)//"`; do\
251257
echo "$$i.scm: $$j" >> $@;\
252258
echo "GFX_FILES += $$i.png" >> $@;\
253-
cat $(SCRIPT_DIR)/gimpscript > $$i.scm.new;\
259+
cat $(GIMP_SCRIPT) > $$i.scm.new;\
254260
grep $$i.png $$j | sed -f $(SCRIPT_DIR)/gimp.sed >> $$i.scm.new;\
255261
echo "(gimp-quit 0)" >> $$i.scm.new;\
256262
cmp -s $$i.scm.new $$i.scm || cp $$i.scm.new $$i.scm;\

scripts/gimpscript-v2

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
;----------script-fu-set-all-layers-invisible----------
2+
;procedure by Hevan53
3+
;------------------------------------------------------
4+
5+
(define (script-fu-set-all-layers-invisible inImage inDrawable)
6+
(let* (
7+
(layers (gimp-image-get-layers inImage))
8+
(num-layers (car layers))
9+
(layer-array (cadr layers))
10+
(theLayer)
11+
)
12+
13+
(gimp-image-undo-group-start inImage)
14+
15+
(while (> num-layers 0)
16+
(set! num-layers (- num-layers 1))
17+
(set! theLayer (aref layer-array num-layers))
18+
(if (= (car (gimp-drawable-get-visible theLayer) ) TRUE)
19+
(gimp-drawable-set-visible theLayer FALSE)
20+
)
21+
)
22+
23+
(gimp-image-undo-group-end inImage)
24+
(gimp-displays-flush)
25+
26+
)
27+
)
28+
29+
;--------------------save-layers-----------------------
30+
;procedure by planetmaker
31+
;
32+
; // List of source and target images followed by a list of layer names
33+
; // in the source image which will make up the target image.
34+
;
35+
; // Example:
36+
; // (save-layers "source-file-name" "target-file-name" '(layername1 layername2 layername3 ...))
37+
;------------------------------------------------------
38+
(define
39+
(
40+
save-layers
41+
42+
inImageName
43+
outImageName
44+
inLayerNames
45+
)
46+
(let*
47+
(
48+
(image (car (gimp-file-load RUN-NONINTERACTIVE inImageName inImageName)))
49+
(visibleStuff (car (gimp-image-get-active-layer image)))
50+
(layers (gimp-image-get-layers image))
51+
(num-layers (car layers))
52+
(layer-array (cadr layers))
53+
(thisLayer -1)
54+
(thisNumLayers 0)
55+
(theseLayers layers)
56+
(thisLayerName 0)
57+
58+
(layerNames inLayerNames)
59+
)
60+
61+
; First make everything invisble
62+
(script-fu-set-all-layers-invisible image image)
63+
64+
; Now make those layers visible which were asked to become visible
65+
66+
; iterate through all layers of the image
67+
(while (> num-layers 0)
68+
(set! num-layers (- num-layers 1))
69+
(set! thisLayer (aref layer-array num-layers))
70+
(set! thisLayerName (car (gimp-drawable-get-name thisLayer)))
71+
; (gimp-message (string-append "Image Layer-Name: " thisLayerName))
72+
73+
; iterate through all layer Names we shall use
74+
(set! layerNames inLayerNames)
75+
(while (not (null? layerNames))
76+
; if layerName matches this user supplied layername: make it visible
77+
(if (string=? (car layerNames) thisLayerName)
78+
(gimp-drawable-set-visible thisLayer TRUE)
79+
)
80+
(set! layerNames (cdr layerNames))
81+
)
82+
)
83+
84+
; Merge all visible layers into one layer which we then save to the given filename
85+
(set! visibleStuff (car (gimp-image-merge-visible-layers image CLIP-TO-IMAGE)))
86+
(file-png-save RUN-NONINTERACTIVE image visibleStuff outImageName outImageName 0 9 0 0 0 0 0)
87+
(gimp-image-delete image)
88+
)
89+
)
90+
91+
92+
; // ===================================================================
93+
; // List of source and target images followed by a list of layer names
94+
; // in the source image which will make up the target image.
95+
; // Example:
96+
; // (save-layers "source-file-name" "target-file-name" '(layername1 layername2 layername3 ...))
97+
; // ===================================================================

0 commit comments

Comments
 (0)