; script-fu-dmm-old-photo ; A file-filter script to make an image look like an old, worn, photograph. ; The core operations here are adapted from Chris Gutteridge's ; script-fu-old-photo, distributed stock with The GIMP 1.2, ; but with many changes. ; ; script-fu-dmm-old-photo puts a fuzzy border around the image and ; modifies the color balance (the default conversion is to "sepia"). ; Values controlling these two transformations are supplied as parameters ; (this makes it easy to use this script for, say, blending in to web page ; backgrounds of any solid color; it is also nice for batch scripting). ; ; (If all you need to do is use the fuzzy border interactively for ; blending into a background, using Gutteridge's script-fu-fuzzy-border ; interactively would be easier.) ; ; Parameters: ; border-width fuzzy border width, in pixels, integer ; granularity granularity within fuzzy border, integer ; (see script-fu-fuzzy-border below) ; Example: 10 2 gives a 10 pixel fuzzy border ; 10 8 gives a 10 pixel fuzzy border, but the ; image runs up against the edge sharply; not good ; border-red fuzzy border color, RGB triplet in integers or floats ; border-green ; border-blue ; cyan-red color balance, values -100 <= x <= 100 ; magenta-green in integers or floats ; yellow-blue ; Example: 100 0 0 turns the image reddish ; infile.png Input image file, must be a PNG ; outfile.png Output image file, will be a PNG ; ; Example Numbers: ; 10 2 255 255 255 30 0 -30 ; thin fuzzy white border on "sepia-toned" image ; 10 2 255 0 0 0 0 100 ; thin fuzzy red border on image color-balanced to blue ; ; Differences: ; Unlike script-fu-old-photo, script-fu-dmm-old-photo does not ; "defocus" (gaussian RLE blur) or "mottle" (noisify and blur) the image. ; I prefer my old photographs to be crisp (as, aside from deliberate ; effects, old real photographs tend to be). ; This Script-Fu also differs from script-fu-old-photo in that it is ; designed to read and write files, making it suitable for batch processing ; from the bash command line. ; ; If you modify this Script-Fu, please change its name (use something ; other than "-dmm-", at least). ; ; This Script-Fu must be put in The GIMP's script directory ; (e.g., $HOME/.gimp-1.2/scripts). ; For command-line invocation, use the shell script script-fu-dmm-old-photo.sh ; For interactive invocation, run The GIMP and go to ; Xtns -> Script-Fu -> dmm ; (define (script-fu-dmm-old-photo border-width granularity border-red border-green border-blue cyan-red magenta-green yellow-blue infile outfile) (let* ((image (car (file-png-load 1 infile infile))) ; get the "active drawable" ; Question: Is this the entire image when loading a PNG or JPG? ; If not, then the use of gimp-image-active-drawable ; is a bug, and something such as gimp-image-flatten ; should be used instead. (drawable (car (gimp-image-active-drawable image))) ) ; Send all (gimp-message "foo") messages to stdout, not popup windows ; Useful for debugging in batch mode (gimp-message-set-handler 1) ; NOTE: Do the sepia toning *before* the fuzzy border, so that ; the fuzzy border colors will be maintained. ; This is the opposite of what Gutteridge's script-fu-old-photo ; does, but it's ok there since he uses white (255 255 255) ; for the fuzzy border. ; The desaturation step to follow requires an RGB image. ; Here, detect any non-RGB or RGBA image and, if necessary, ; convert it to RGB. (Note: converting the image converts ; the drawable as well). (if (> (car (gimp-drawable-type drawable)) 1) (gimp-convert-rgb image) () ) ; Use desaturation rather than conversion to grayscale because ; that's what script-fu-old-photo does. (gimp-desaturate drawable) ; This step is used in script-fu-old-photo to fade the image. ; I omit it, because to me the past isn't faded, just monochrome ;-) ;(gimp-brightness-contrast drawable -20 -40) (gimp-color-balance drawable 0 TRUE cyan-red magenta-green yellow-blue) ; transfer mode: 0=shadow, 1=midtones, 2=highlights ; preserve luminosity values at each pixel? ; cyan/red color balance (-100 <= cyan/red <= 100) ; magenta/green color balance ; yellow/blue color balance ; script-fu-old-photo uses 30 0 -30, ; which brings the red up a little bit ; and the yellow up (blue down) a little bit ; Eric R. Jeschke uses a quite different method ; in his "Sepia Toning" tutorial at gimp.org ; Note: His sepia RGB triplet is 162 138 101 ; In percentages, that's 63 54 39 ; see /usr/share/gimp/VERSION/scripts/fuzzyborder.scm for source (script-fu-fuzzy-border image drawable (list border-red border-green border-blue) border-width TRUE granularity FALSE 100 FALSE TRUE ) ; Fade-to color as RGB triplet. Change this to fade to ; differently colored backgrounds. This color does not ; affect the image color itself. ; approximate border width, in pixels ; I prefer a narrower border (10); this means that ; the granularity must go down (I like 2; 4 seems to ; work), or the image will have sharp cut-offs at ; the edges at some points. ; script-fu-old-photo default is 20 (w/granularity 8) ; blur border (Gauss RLE)? ; granularity (1 is low) ; script-fu-old-photo default is 8 ; add shadow? ; shadow weight (percent) ; work on copy? ; flatten image? ; ; Must flatten the image, or the border changes above don't ; get saved to file below. (set! drawable (car(gimp-image-flatten image))) ; Save as a PNG (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 ; I always forget these ... "script-fu-dmm-old-photo" ; script name to register "/Xtns/Script-Fu/dmm/sfdmm-old-photo" ; where it goes "fuzzy border, sepia tone; no defocus, mottle" ; script description "David M. MacMillan" ; author "Copyright 2004 by David M. MacMillan; GNU GPL" ; copyright "2004-02-11" ; date "RGB*, GRAY*" ; valid types of image ; default parameters SF-VALUE "border-width" "10" ; fuzzy border SF-VALUE "granularity" "2" SF-VALUE "border-red" "255" SF-VALUE "border-green" "255" SF-VALUE "border-blue" "255" SF-VALUE "cyan-red" "30" ; image color balance SF-VALUE "magenta-green" "0" ; default is "sepia" SF-VALUE "yellow-blue" "-30" SF-FILENAME "infile" "infile.png" SF-FILENAME "outfile" "outfile.png" ) ; Copyright 2004 by David M. MacMillan ; This work 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. ; NOTICE OF DISCLAIMER OF WARRANTY AND LIABILITY: ; This work is distributed 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. ; In no event will the author(s), editor(s), or publisher(s) of this work ; be liable to you or to any other party for damages, ; including but not limited to any general, special, incidental ; or consequential damages arising out of your use of or inability to use this ; work or the information contained in it, even if you have been advised ; of the possibility of such damages. ; In no event will the author(s), editor(s), or publisher(s) of this work ; be liable to you or to any other party for any injury, death, ; disfigurement, or other personal damage arising out of your use of ; or inability to use this work or the information ; contained in it, even if you have been advised of the ; possibility of such injury, death, disfigurement, or other ; personal damage. ; You should have received a copy of the GNU General Public License ; along with this work; if not, write to the ; Free Software Foundation, Inc., 59 Temple Place - Suite 330, ; Boston, MA 02111-1307, USA.