Gimp Script-Fu: motivation for learning Lisp/Scheme/Clojure

If you ever want to find some motivation for learning Lisp/Scheme/Clojure programming, I was reminded recently that plugins for Gimp are written in Scheme. The makers of (Paul Sherman, I think) have a nice collection of plugins for Gimp 2.8 that you can download, and they’re all written in Scheme.

As just one example, the following source code is for a plugin named “Change Contrast”:

; FU_contrast_change-contrast.scm
; version 2.7 []
; last modified/tested by Paul Sherman
; 05/05/2012 on GIMP-2.8
; ------------------------------------------------------------------
; Original was "Vivid saturation" script  for GIMP 2.4
; by Dennis Bond with thanks to Jozef Trawinski
; Modified for use in GMP-2.4 by Paul Sherman 
; This is modification 2 made on 11/15/2007
; distributed by
(define (FU-shadows-highlights image drawable shadows highlights)

	;Start an undo group so the process can be undone with one undo
	(gimp-image-undo-group-start image)

	; create a highlights layer
	(let ((highlights-layer (car (gimp-layer-copy drawable 1))))
	(gimp-item-set-name highlights-layer "fix highlights (adjust opacity)")
	(gimp-image-insert-layer image highlights-layer 0 -1)

	;process shadows/highlights layer
	(gimp-desaturate highlights-layer)
	(gimp-invert highlights-layer)
	(gimp-layer-set-mode highlights-layer 5)
	(plug-in-gauss-iir2 1 image highlights-layer 25 25)

	;copy highlights layer to create shadows layer
	(define shadows-layer (car (gimp-layer-copy highlights-layer 1)))
	(gimp-item-set-name shadows-layer "fix shadows (adjust opacity)")
	(gimp-image-insert-layer image shadows-layer 0 -1)

	;process highlights layer
	(plug-in-colortoalpha 1 image highlights-layer '(255 255 255))
	(gimp-layer-set-opacity highlights-layer highlights)

	;process shadows layer
	(plug-in-colortoalpha 1 image shadows-layer '(0 0 0))
	(gimp-layer-set-opacity shadows-layer shadows)

	;Finish the undo group for the process
	(gimp-image-undo-group-end image)

	;update image window

(script-fu-register "FU-shadows-highlights"
		"<Image>/Script-Fu/Contrast/Change Contrast"
		"Removes shadows and highlights from a photograph, makes image feel more saturated"
		"Dennis Bond - thanks to Jozef Trawinski"
		"Dennis Bond - thanks to Jozef Trawinski"
		"October 26, 2006"
		SF-IMAGE "Image" 0
		SF-DRAWABLE "Drawable" 0
		SF-ADJUSTMENT "Shadows"    '(50 0  100   1   1   0   0)
		SF-ADJUSTMENT "Highlights" '(0  0  100   1   1   0   0)

What this code does isn’t too important at the moment. I just wanted to share an example of what a Gimp plugin looks like. If you want to learn how to write Gimp plugins, this seems like the best URL to start at.

IMHO, what happens here is that if you don’t mind all the parentheses, it’s pretty easy to pick up Lisp/Scheme/Clojure, and then what happens is that you need to learn the Gimp developer API. When you’re ready for that, what you want to do is fire up the Gimp Procedure Browser.

I don’t currently have any plans to write Gimp plugins, but if I do, I’ll be starting at those two URLs. (I already have read them, but I have so many things going on right now I don’t have time to dive into something new atm.)

In summary, if you are looking for motivation for learning Lisp/Scheme/Clojure, writing a Gimp plugin seems like a cool, practical playground.

This website is a little one-man operation. If you found this information helpful, I’d appreciate it if you would share it.

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Enter the characters shown in the image.