User:Branko/Flatten, BW, Save

From DPWiki
Jump to navigation Jump to search

This GIMP script will perform the following functions on a scan, in this order:

  • "flatten" the image (= merge all layers if necessary)
  • convert from greyscale to black/white indexed
  • save

Update: minor update 1.01 to make this work with GIMP 2.4.

Workflow

This script helps me when cleaning up my image scans. It lives under <image>/Script-Fu/Alchemy/Flatten, BW, Save, but I have assigned function key F11 to it, so that a number of mouse clicks and key presses come together in one key press.

I have a number of other GIMP functions under Function keys, notably:

  • F2, flatten image (not related to DP, just very handy for my work as a web developer)
  • F3, mode to Greyscale (for some reason, my scanner produces Indexed images)
  • F4, Threshold

Steps are:

  1. load image
  2. mode to Greyscale (F3)
  3. if necessary: rotate
  4. threshold
  5. clean with the eraser (I try and leave some 'dirt' on blank pages, so that it is clear to the proofreader that the scan displays correctly)
  6. flatten, b/w, save (F11)

Installation

If you want to use this script, open the Preferences dialog (<toolbox>/File/Preferences), and go to Folders/Scripts. There you will see the location where you could save this script. You may wish to pick the location that you include in your personal back-ups.

If you're already running the GIMP and don't wish to restart, select the Xtns / Script-fu / Refresh scripts menu to load your new script. You can also use this menu to reload existing scripts, for instance if you are making changes to this script as you go.

Future

If you have already taken one of the steps manually and then execute the script, it may halt with an error message. If you like, I could make every step conditional on being necessary.

Let me know what else you need.

Update 12 October 2022: hi, this is Branko from the future! Today I discovered that even though I hadn't used this script for at least 7 years, it still works.

Download

Just copy and paste to a text file called 'flatten-bw-save.scm', next see Installation.

; ----begin script----
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.  
; 
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
; 
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;
; flatten-bw-save.scm   version 1.00   2006/05/25
;
; CHANGE-LOG:
; 1.00 - initial release
; 1.01 - adapted for GIMP 2.4
;
; Copyright (C) 2006-2009 Branko Collin <collin@xs4all.nl>
;
; Flattens an image, converts it to b/w indexed, saves.

(define nlayer 0)
(define filename "")
(define (script-fu-flatten-bw-save image layer)

  (set! nlayer (car (gimp-image-flatten image)))
  (gimp-image-convert-indexed image 0 3 2 0 0 "")
  (set! filename (car (gimp-image-get-filename image)))
  (gimp-file-save 1 image nlayer filename filename)
  (gimp-image-clean-all image)
)

(script-fu-register "script-fu-flatten-bw-save"
		    "Flatten, B/W, Save"
		    "Flattens an images, converts it to indexed black and white, saves and closes an image. Handy for preparing scans for Project Gutenberg OCR."
		    "Branko Collin"
		    "Branko Collin"
		    "2006"
		    ""
 		    SF-IMAGE       "Image"               0
		    SF-DRAWABLE    "Drawable"            0)

(script-fu-menu-register "script-fu-flatten-bw-save"
			 _"<Image>/Script-Fu/Alchemy")
; ----end script----