Debian Codegraph @

src/ui/gui-images/convert-to-png.scm

raw symbols SCIP
1 ;; Convert given PATTERN to pngs.
2 ;; Following https://www.gimp.org/tutorials/Basic_Batch/ .
3 ;; See also https://schemers.org/Documents/Standards/R5RS/HTML/ for basic Scheme functions.
4
5 ;; TODO: This is unused, because of 2 TODOs below.
6 ;; The ImageMagick conversion works reliably in batch mode, see convert-to-png.sh .
7
8 (define (convert-to-png pattern)
9 (let* ((filelist (cadr (file-glob pattern 1))))
10 (while (not (null? filelist))
11 (let* ((filename (car filelist))
12 (filename-without-ext (substring filename 0 (- (string-length filename) 4)))
13 (export-filename (string-append filename-without-ext ".from-gimp.png"))
14 (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
15 ;; Necessary to correctly export images with multiple layers, like ButtonDisabled.xcf .
16 ;; TODO: while it works, it seems to remove alpha from the layer (even it was already applied mask).
17 (flattened-layer (gimp-image-flatten image))
18 ;; Necessary to correctly export images with unapplied mask in xcf, like FrameThickWhite.xcf .
19 ;; TODO: it fails to apply mask in resulting file.
20 (gimp-layer-remove-mask flattened-layer MASK_APPLY)
21 (drawable (car flattened-layer))
22 )
23 (gimp-message (string-append "Converting " filename " to " export-filename " using GIMP"))
24 (gimp-file-save RUN-NONINTERACTIVE
25 image drawable export-filename export-filename)
26 (gimp-image-delete image)
27 )
28 (set! filelist (cdr filelist))
29 )
30 )
31 )
32
33 (convert-to-png "*.xcf")