I am trying to write a spritesheet packing script for gimp
er it is:
(define pack-sprites
(let* (
(cols 5)
(rows 3)
(sprite_width 750)
(sprite_height 1026)
(image (car(vector->list(cadr(gimp-image-list)))))
(layers (vector->list(cadr(gimp-image-get-layers image))))
)
(let loop ((i 0 ))
(if (< i 14))
(begin
(let* (
(offx (* sprite_width (modulo i cols)))
(offy (* sprite_height (floor (/ i cols))))
(layer car(layers))
(set! layers (cdr(layers)))
)
(gimp-layer-translate layer offx offy)
(loop (+ i 1) )
)
)
)
)
)
(script-fu-register
"pack-sprites"
"<Image>/Tools/pack sprites"
"pack layers into spritesheet"
"plugnpi"
"plugnpi"
"March 2025"
"RGB*, GRAY*"
)
After running refresh-scripts i get this error :
Error while loading /home/user/.config/GIMP/2.10/scripts/packer.scm:
Error: (/home/user/.config/GIMP/2.10/scripts/packer.scm : 26)
Invalid type for argument 1 to gimp-layer-translate
The type of layer is just a numeric id, right? somehow I must have something weird in layer idk what's going on.
Far from being a scheme expert but if I add a (print layer)
just before the gimp-layer-translate
I get:
#<car PROCEDURE 74>
Error: Invalid type for argument 1 to gimp-layer-translate
The layers
list is OK so it must be a problem with the (layer car(layers))
but I can't put my finger on it. Using (layer (car layers))
seems more appropriate but makes the filter hang.
Edit: using your Github version
(gimp-layer-translate ...)
is always applied to the same first layer. When I kill the script, the first layer has offsets (2115000, 203255730)
.(gimp-layer-set-offsets layer offx offy)
By the way, if you register your procedure with a SF-IMAGE
argument the current image will be passed to the script. As written your script can only work on the last opened image.
Also, if your Gimp has Python support (flatpak or AppImage versions, since you are on Linux), you can use the ofn-layer-tiles
script.