Skip to content

Instantly share code, notes, and snippets.

@sgeos
Last active July 27, 2023 01:23
Show Gist options
  • Save sgeos/6436944379d34e4f9e0839d587557c56 to your computer and use it in GitHub Desktop.
Save sgeos/6436944379d34e4f9e0839d587557c56 to your computer and use it in GitHub Desktop.
gimp-batch-coloring-book-convert.scm
(map
(lambda (image)
(gimp-image-undo-group-start image)
(define fullpath (car (gimp-image-get-filename image)))
(define filename (car (reverse (strbreakup fullpath "/"))))
(define path (car (strbreakup fullpath filename)))
(define basefilename (car (strbreakup filename ".")))
(define xcfpath (string-append path basefilename ".xcf"))
(define linepath (string-append path "bw_" basefilename ".png"))
(define colorpath (string-append path "color_" basefilename ".png"))
(define width 2200)
(define height 3300)
(define contrast 0.95)
(define ppi 300)
(gimp-image-scale-full image width height INTERPOLATION-CUBIC)
(gimp-image-set-resolution image ppi ppi)
(define color_layer (car (gimp-image-get-active-layer image)))
(gimp-item-set-name color_layer "Color")
(plug-in-gauss-iir RUN-NONINTERACTIVE image color_layer 3 3 3)
(define line_layer (car (gimp-layer-new-from-drawable color_layer image)))
(gimp-item-set-name line_layer "Line")
(gimp-image-insert-layer image line_layer 0 0)
(gimp-drawable-desaturate line_layer 1)
(plug-in-unsharp-mask RUN-NONINTERACTIVE image line_layer 3.0 11.0 0)
(gimp-drawable-brightness-contrast line_layer contrast 1)
(gimp-file-save RUN-NONINTERACTIVE
image
line_layer
linepath
linepath
)
(define mask_layer (car (gimp-layer-new-from-drawable line_layer image)))
(gimp-item-set-name mask_layer "Mask")
(gimp-image-insert-layer image mask_layer 0 1)
(gimp-layer-set-mode mask_layer LAYER-MODE-LUMA-DARKEN-ONLY)
(plug-in-color-enhance RUN-NONINTERACTIVE image color_layer)
(gimp-drawable-set-visible line_layer FALSE)
(gimp-image-set-active-layer image line_layer)
(gimp-file-save RUN-NONINTERACTIVE
image
color_layer
xcfpath
xcfpath
)
(define color_image (car (gimp-image-duplicate image)))
(define color_image_layer (car (gimp-image-merge-visible-layers color_image CLIP-TO-IMAGE)))
(gimp-file-save RUN-NONINTERACTIVE
color_image
color_image_layer
colorpath
colorpath
)
(gimp-image-delete color_image)
(gimp-image-undo-group-end image)
(list image line_layer mask_layer color_layer)
)
(vector->list (cadr (gimp-image-list)))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment