(define (my-thumbnailer image drawable size sharp dir)
  (let* (
      (width  (car (gimp-drawable-width drawable)))
      (height (car (gimp-drawable-height drawable)))
      (new_width size)
      (new_height size)
    )

    (gimp-image-undo-group-start image)

    (if (= dir 0)
      (if (> width height)
        (begin (set! new_height (/ (* size height) width))
        )
        (begin (set! new_width (/  (* width size) height))
        )
      )
    )
    (if (= dir 1)
      (begin (set! new_height (/ (* height size) width))
      )
    )
    (if (= dir 2)
      (begin (set! new_width (/ (* width size) height))
      )
    )

    (gimp-drawable-transform-scale-default drawable
		0 0 new_width new_height 1 0)
    (gimp-image-resize-to-layers image)
    (plug-in-sharpen 1 image drawable sharp)
    (gimp-image-flatten image)

    (gimp-image-undo-group-end image)

    (gimp-displays-flush)
  )
)

(script-fu-register "my-thumbnailer"
	_"<Image>/Script-Fu/Utils/Make thumbnail..."
	"Do nothing"
	"Joey User"
	"Joey User"
	"August 2000"
	""
	SF-IMAGE      "Input Image"	0
	SF-DRAWABLE   "Input Drawable"	0
	SF-VALUE      "Size"		"150"
	SF-ADJUSTMENT "Sharpening"	'(30 0 100 1 10 1 1)
	SF-OPTION     "Direction"	'("Largest" "Horizontal" "Vertical")
)
