- Fun with GIMP's Script-Fu
- 15 Nov 2011 09:10:11 pm Permalink
So as many of you know, although I haven't formally announced it yet, I am working on a book about calculators (further details coming soon) and it will of course have tons of screenshots in it. The best way to take screenshots is with my favorite emulators, but unfortunately, the format of the screenshots they take is not acceptable for a book. For one, the default resolution is 72x72 pixel per inch, while I need 300 pixels per inch. Of course, once the resolution is changed, they're miniature, so I need to scale them up, remote the screen-colored yellowish color, and add a border. Today, because I'm dumb, I spent a few hours figuring out how to script that up in GIMP; below you can see the results of my hard work. I do recommend giving it a try if you have any tasks of your own in GIMP that you do a lot and need to automate, especially if you either know or want to know LISP/Lush/Scheme.
(define (manning-TI-SS img)
(let* ((numlayers (car (gimp-image-get-layers img)))
(layerlist (cadr (gimp-image-get-layers img)))
;delete the non-bottom layers
(set! count (- numlayers 1))
(while (> count 0)
(set! count (- count 1))
(gimp-image-remove-layer img (aref layerlist count))
(gimp-threshold (aref (cadr (gimp-image-get-layers img)) 0) 128 255)
(gimp-image-set-resolution img 300 300)
(gimp-image-scale-full img 576 384 INTERPOLATION-NONE)
(gimp-image-resize img 582 390 3 3)
(let* ((mylayer (car (gimp-layer-new img 582 390 RGBA-IMAGE "border" 100 NORMAL-MODE)))
(mylayer2 (car (gimp-layer-new img 582 390 RGBA-IMAGE "border" 100 NORMAL-MODE))))
(gimp-image-add-layer img mylayer -1)
(gimp-image-set-active-layer img mylayer)
(gimp-selection-shrink img 2)
(gimp-bucket-fill mylayer FG-BUCKET-FILL NORMAL-MODE 100 0 0 0 0)
(gimp-image-add-layer img mylayer2 0)
(gimp-image-lower-layer-to-bottom img mylayer2)
(gimp-image-set-active-layer img mylayer2)
(gimp-bucket-fill mylayer2 BG-BUCKET-FILL NORMAL-MODE 100 0 0 0 0)
; Finally register our script with script-fu.
"Manning TI Screenshot"
"Processes a raw .gif screenshot for inclusion in my book."
"Kerm Martian <email retconned>"
SF-IMAGE "Image" 0)
(script-fu-menu-register "manning-TI-SS" "<Toolbox>/Xtns/Script-Fu")