More Gimp Scripting

This is a script-fu to do a perspective transformation of an image. As usual, this needs to be saved as text with the .scm extension in your Gimp scripts folder. You may have to a 'Refresh Scripts' to get it to show up.

;  Perspective Transform
;  Transforms an image using a perspective transformation


(define (perspective-transform infile)
  (let* ((image (car (file-png-load 1 infile infile)))
         (drawable (car (gimp-image-active-drawable image)))
         )
  (set! newlayer (car (gimp-image-get-active-layer image)))
  (set! width  (car (gimp-drawable-width newlayer)))
  (set! height (car (gimp-drawable-width newlayer)))
  (set! outfile (string-append infile "-temp.png"))
  (set! x0 0)
  (set! y0 0)
  (set! x1 (/ size 2))
  (set! y1 (/ size 3))
  (set! x2 0)
  (set! y2 size)
  (set! x3 (/ size 2))
  (set! y3 (* 2 (/ size 3)))
  (gimp-drawable-transform-perspective-default drawable x0 y0 x1 y1 x2 y2 x3 y3 0 1 )
  (file-png-save 1 image drawable outfile outfile 1 0 0 0 0 0 0 )
            ; 1 Adam7 interlacing?
            ;   0 deflate compression factor (0-9)
            ;     0 Write bKGD chunk?
            ;       0 Write gAMMA chunk?
            ;         0 Write oFFs chunk?
            ;           0 Write tIME chunk?    ?? backwards in DB Browser
            ;             0 Write pHYS chunk?  ?? backwards in DB Browser
  )
)

(script-fu-register "perspective-transform"
		    "Perspective transformation"
		    "This takes an image and creates a perspective transformation of the image."
		    "David Wees<dweesdesign@gmail.com>"
		    "David Wees - released under GNU Public license"
		    "2007"
		    ""
		    SF-FILENAME   "infile" "infile.png"
)
(script-fu-menu-register "perspective-transform" "<Toolbox>/Xtns/Script-Fu/Misc")