;; GIMP "save area" function, (c) Silas S. Brown 2005, 2007. Version 1.1 ;; License: GPL ;; INSTALLATION INSTRUCTIONS ;; ------------------------- ;; 1. If you haven't already run the Gimp, run it. ;; 2. Find your .gimp directory. On Unix this will be in ;; your home directory, called .gimp or .gimp-1.2 or ;; similar (if there's more than one then pick the one that ;; corresponds to the version of The GIMP that you're ;; using). On Windows it'll probably be in ;; C:\Documents and Settings\your user ID\.gimp-2.2 or ;; similar (in other words it will be in the CygWin home ;; directory) or you can find it by searching all files and ;; folders for .gimp. ;; 3. Save this file (savearea.scm) into the "scripts" ;; subdirectory of the .gimp directory. ;; 4. Open a new image, right-click on it, go to "File", ;; and there should be an option called "Save area". It's ;; a good idea to assign a shortcut key to it (personally I ;; use the slash key, /). In some versions of The GIMP, ;; all you have to do is point at this option and then ;; press the shortcut key that you want to assign to it ;; (and it will then appear next to the menu item). In ;; other versions of The GIMP, you will have to go to the ;; main window (not the image window) and navigate through ;; File / Preferences / Interface / Configure keyboard ;; shortcuts / Plug-ins, find "Save area" somewhere in the ;; long list that appears, and then type the shortcut key. ;; 5. While configuring The GIMP, I also recommend choosing ;; the Selection tool (the box) if it's not already chosen, ;; and going to File/Preferences/Input Devices and press ;; "Save Input Device Settings Now". This will cause The ;; GIMP to load with the selection tool by default, which is ;; useful if you do more work with selections than with ;; actual drawing. (Older versions of The GIMP had the ;; selection tool as the default anyway.) ;; 6. You should now be able to make a selection and then ;; use that shortcut key to save it quickly, then make ;; another selection and so on. If this doesn't work in ;; your version of The GIMP then try converting the input ;; images into a different format first (you can use netpbm ;; or imagemagick to batch-convert if necessary). ;; END OF INSTALLATION INSTRUCTIONS ;; ------------------------------------------------------ (define (saveArea img layer) (let* ((selection (gimp-selection-bounds img)) (x1 (cadr selection)) (y1 (caddr selection)) (x2 (car (cdr (cdr (cdr selection))))) (y2 (car (cdr (cdr (cdr (cdr selection)))))) (width (- x2 x1)) (height (- y2 y1)) (newType (car (gimp-image-base-type img))) (myNewType (if (equal? newType 1) 1 0)) ;; "indexed" type (2) is awkward so convert it to RGB (0). May get a completely-black area anyway, but at least will be able to save as PNG to get the dimensions for derotate.sh. For other uses I suggest batch-converting first as mentioned in instructions above. (newImg (car (gimp-image-new width height myNewType))) (newLayer (car (gimp-layer-new newImg width height (* myNewType 2) "layer 1" 100 NORMAL))) (_ (gimp-image-add-layer newImg newLayer 0)) (disp (car (gimp-display-new newImg))) ;; MUST do this otherwise gimp may corrupt when save (_ (gimp-edit-copy layer)) (floatingLayer (car (gimp-edit-paste newLayer 0))) (_ (gimp-floating-sel-anchor floatingLayer)) (_ (plug-in-autocrop 1 newImg newLayer)) (file (car (gimp-temp-name "-area.png"))) (_ (file-png-save 1 newImg newLayer file file 0 9 0 0 0 0 0)) (_ (gimp-display-delete disp)) ) ())) (script-fu-register "saveArea" "/File/Save area" "Saves the selected area to a PNG file" "Silas S. Brown" "Silas S. Brown" "2005" "" ; any image type SF-IMAGE "Image" 0 SF-DRAWABLE "Layer" 0 )