#!/usr/local/bin/bash # ----------------------------------------------------------------------------- # "600 dpi scan cleaner and screen-size scaler" # Just the thing for converting high-resolution (but very low quality) scans # into high-quality screen-sized JPEGs. # # Typical usage is something like: # # 1. One-off operation: # $ scancleaner foo.png foo_screensized.jpg # # 2. Fix all the JPEG files in the current directory: # $ for i in *jpg; do echo $i; scancleaner $i ${i%.jpg}_r.Jpg; done # # Note that the sel-guass operations can take a _lot_ of time and memory! # (My AthonXP2000+ can take over 9 minutes on a 2500x3500 pixel image.) # ----------------------------------------------------------------------------- # Copyright 2003 Chris Baird # Bound to the GNU Public Licence Version 2. # ----------------------------------------------------------------------------- sfile=${1} tfile=${2-output.jpg} twidth=1024 # size of the output image theight=768 # (i.e, that of most desktops) gimp -i -b ' (begin (define (make-clean sfile tfile twidth theight) (let* ( (image (car (gimp-file-load 1 sfile sfile))) (drawable (car (gimp-image-active-drawable image))) (swidth (car (gimp-image-width image))) (sheight (car (gimp-image-height image)))) (if (> (* theight swidth) (* sheight twidth)) (set! theight (* sheight (/ twidth swidth))) (set! twidth (* swidth (/ theight sheight)))) (plug-in-sel-gauss 1 image drawable 4 20) (gimp-levels drawable 0 4 251 1.0 0 255) (plug-in-sel-gauss 1 image drawable 16 8) (gimp-image-scale image twidth theight) (plug-in-sel-gauss 1 image drawable 16 4) (gimp-levels drawable 0 4 251 1.0 0 255) (file-jpeg-save 1 image drawable tfile "" 0.95 0.1 1 1 "Made with GIMP" 0 1 0 2) )) (make-clean "'$sfile'" "'$tfile'" '$twidth' '$theight') (gimp-quit 0) ) '