I have just read the tutorial on GIMP about script-fu!
Scripting in GIMP is pretty easy, but debuging is quite trouble. This tutorial help me a bit, at least, I leart to use 'print' to do basic debug.
Though scheme is not difficult, It would be better if I can do it in python, but I can't found any python-fu tutorial, where is it?
So what I've done? I'm managed to resize a set of images to another fixed size, I try to do it first with ImageMagick by "convert -resize", but ImageMagick doesn't convert the image properly. When I say -resize 130x41, the resulting image is 128x41 (Am I misunderstand this option?). May be it is only some rounding problem but, not acceptable in this case. On the other hand, GIMP do it great, so I try to script it!
The solution is simple. First write a small script-fu, and run gimp in batch mode.
The script is like this:
; It will resize image in batch
(define (bresize filename width height)
; load
(set! img (car(gimp-file-load RUN-NONINTERACTIVE filename filename)))
; not really used, but gimp-file-save need it
(set! lyr (car(gimp-image-get-active-layer img)))
; scale
(gimp-image-scale img width height)
; save
(file-png-save-defaults RUN-NONINTERACTIVE img lyr filename filename)
)
(script-fu-register "bresize"
"
And to run it in a batch, easy!
$ for f in *.png; do \
gimp-2.0 -i -b "(bresize \"$f\" 130 41)" '(gimp-quit 0)'; \
done
2 comments:
Hello,
Your script was helpful to guide me to make my own. I really just needed to open a file, scale it and save the result as a new image format. I use the windows batch to iterate all files in a directory. Only beef is that does not automatically close the script-fu session. I will have to keep looking into it. Good day.
Yemi Bedu
It's really a surprise to me that, this post is still useful!
Post a Comment