GIMP scheme script-fu for pixel art

Posted by (twitter: @axoonaa)
May 3rd, 2016 3:41 pm

I like using GIMP for various reasons. Obviously because it’s free of charge. But also because it offers powerfull scripting tools.

I was doing pixel art for my game this time and I used GIMP to create it. It’s been really the first time I have been creating pixel art if you don’t count my very first Ludum Dare entry were I just made a few pixel sprites.
While doing pixel art you usually need to enlarge your visuals without any interpolation. I know of two ways in which it can be done, either in the code or by embedding images that are already enlarged. While the first option is probably prettier I prefer the simplicity of integrating images that have already the right size. The drawback is that you need to enlarge the images one by one.

That’s why on Saturday I developped a small scipt-fu in scheme for GIMP which enlarges all photos chosen in the input, by a specific ratio, and with chosen interpolation (no interpolation by default). The enlarged photos are created in the output directory.

Well maybe I’m reinventing the wheel but script-fu scripts are very difficult to find on the net and developping in scheme can be really painfull (I don’t know of any existing debugger, anyone?). So I’d like to share my script, maybe someone will find it usefull.

filename: batch-enlarge.scm

(define (script-fu-batch-enlarge globexp outpath ratio inpol)
(define (resize-img n f)
(let* ((fname (car f))
(img (car (gimp-file-load 1 fname fname)))
(outname (string-append outpath (car (gimp-image-get-name img))))
(newy (* (car (gimp-image-height img)) ratio))
(newx (* (car (gimp-image-width img)) ratio)))

(gimp-image-undo-disable img)
(gimp-image-scale-full img newx newy inpol)
(gimp-file-save 1 img (car (gimp-image-get-active-drawable img)) outname outname)
(gimp-image-delete img)
)
(if (= n 1) 1 (resize-img (- n 1) (cdr f)))
)

(let* ((files (file-glob globexp 0)))
(resize-img (car files) (car (cdr files))))
)

(script-fu-register “script-fu-batch-enlarge”
“/Script-Fu/Batch/Enlarge by ratio …”
“Multiple images resize batch process”
“axoona (@axoonaa)”
“Copyright 2016, axoona”
“April 16, 2016”
“”
SF-STRING “Input files” “Absolute path to your input files\\*”
SF-STRING “Out path” “Absolute path to your output files\\”
SF-VALUE “Ratio” “2.0”
SF-VALUE “Interpolation none-0, linear-1, cubic-2, lanczos-3” “0”)

You just need to copy the script file into your GIMP scripts folder (by default it’s something like user\gimp\scripts) and then update script-fu (Filters/script-fu in GIMP).
And the batch should be working.

The final result gives this, at least 33 images were required to create this scene:

screenshot3

And if you’d like to play the game here’s the link: The Great Biohazard Escape


Leave a Reply

You must be logged in to post a comment.

[cache: storing page]