Add gimp script-fu code for cropping tree sprites
This commit is contained in:
parent
0cbc541bce
commit
7f292c3d56
73
scripts/script-fu.scm
Normal file
73
scripts/script-fu.scm
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
;; Utilities
|
||||||
|
|
||||||
|
(define (take count sequence)
|
||||||
|
(reverse
|
||||||
|
(let loop ((res '()) (rem sequence) (n count))
|
||||||
|
(if (or (null? rem) (= 0 n))
|
||||||
|
res
|
||||||
|
(loop (cons (car rem) res) (cdr rem) (- n 1))))))
|
||||||
|
|
||||||
|
(define (skip count sequence)
|
||||||
|
(let loop ((rem sequence) (n count))
|
||||||
|
(if (or (null? rem) (= 0 n))
|
||||||
|
rem
|
||||||
|
(loop (cdr rem) (- n 1)))))
|
||||||
|
|
||||||
|
(define (replace old new sequence)
|
||||||
|
(let ((n (length old)))
|
||||||
|
(let loop ((pre '())
|
||||||
|
(rem sequence))
|
||||||
|
(cond ((null? rem) (append (reverse pre) rem))
|
||||||
|
((equal? old (take n rem))
|
||||||
|
(append (reverse pre) new (skip n rem)))
|
||||||
|
(else (loop (cons (car rem) pre) (cdr rem)))))))
|
||||||
|
|
||||||
|
(define (string-replace old new string)
|
||||||
|
(list->string
|
||||||
|
(replace (string->list old)
|
||||||
|
(string->list new)
|
||||||
|
(string->list string))))
|
||||||
|
|
||||||
|
(define (foreach-image f)
|
||||||
|
(let* ((list-result (gimp-image-list))
|
||||||
|
(count (car list-result))
|
||||||
|
(ids (cadr list-result)))
|
||||||
|
(do ((i 0 (+ i 1)))
|
||||||
|
((>= i count))
|
||||||
|
(f (vector-ref ids i))))
|
||||||
|
(gimp-displays-flush))
|
||||||
|
|
||||||
|
(define (export-png image path)
|
||||||
|
(gimp-context-push)
|
||||||
|
(let* ((original-active-layer (car (gimp-image-get-active-drawable image)))
|
||||||
|
(temp-image (car (gimp-image-duplicate image)))
|
||||||
|
(merged-layer
|
||||||
|
(car (gimp-image-merge-visible-layers temp-image CLIP-TO-IMAGE))))
|
||||||
|
(file-png-save-defaults RUN-NONINTERACTIVE
|
||||||
|
temp-image merged-layer path path)
|
||||||
|
(gimp-image-delete temp-image)
|
||||||
|
(gimp-image-set-active-layer image original-active-layer))
|
||||||
|
(gimp-context-pop))
|
||||||
|
|
||||||
|
(define (active-image)
|
||||||
|
(vector-ref (cadr (gimp-image-list)) 0))
|
||||||
|
|
||||||
|
;; Cropping tree sprites
|
||||||
|
|
||||||
|
(define (crop-to-middle-sprite image)
|
||||||
|
(let* ((width (car (gimp-image-width image)))
|
||||||
|
(height (car (gimp-image-height image)))
|
||||||
|
(sprite-width (quotient width 3)))
|
||||||
|
(gimp-image-crop image sprite-width height sprite-width 0)
|
||||||
|
(gimp-displays-flush)))
|
||||||
|
|
||||||
|
(define (tree-sprite-export-path image)
|
||||||
|
(string-replace "originals/Cute_Fantasy/Trees" "sprites/trees"
|
||||||
|
(car (gimp-image-get-filename image))))
|
||||||
|
|
||||||
|
(define (export-tree-sprite image)
|
||||||
|
(export-png image (tree-sprite-export-path image)))
|
||||||
|
|
||||||
|
(define (crop-and-export-tree-sprite image)
|
||||||
|
(crop-to-middle-sprite image)
|
||||||
|
(export-tree-sprite image))
|
Loading…
x
Reference in New Issue
Block a user