; IndexGen - a script for the script-fu program ; Copyright (C) 2002-2003 Daniel Ryde ; ; 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. ; ; ; ; IndexGen v1.3 - Script-Fu Image thumbnail indexer for The GIMP ; ; This program generates an image of thumbnail images from ; a filelist. It can have defined space between the thumbnails and ; optionally blend the thumbnails into each other. ; See an examle at my website http://www.ryde.net/photo/ ; ; To generate the filelist you can use the command "find", example: ; find -name *.jpg > /tmp/file.lst ; ; You should probably use a GIMP version higer or equal to 1.2.3. ; I had some trouble with stability in earlier versions using ; this script. ; ; To install this script, copy it to your GIMP script dir: ; cp indexgen.scm $HOME/.gimp-1.2/scripts/ ; and select from the GIMP menu Xtns -> Script-Fu -> Refresh. ; Now you will find it in menu Xtns -> Script-Fu -> Misc. ; ; This program was made by Daniel Ryde in the hope it will be useful ; email: daniel@ryde.net ; web: http://www.ryde.net/ ; (define (trunc x)(- x (fmod x 1))) (define (read-line file-stream) (let* ( (line "") (c 0) ) (while (begin (set! c (fread 1 file-stream)) (and (not (equal? "\n" c)) (not (equal? () c))) ) (set! line (string-append line c)) ) (if (equal? line "") (set! line ()) ()) line) ) (define (paste-thumb img thumb-width thumb-height height-adjust) (let ( (thumb-layer (car (gimp-layer-new img thumb-width (+ thumb-height height-adjust) RGB-IMAGE "Thumb Layer" 100 NORMAL))) ) (gimp-image-add-layer img thumb-layer 0) (let ( (floating-sel (car (gimp-edit-paste thumb-layer FALSE))) ) (gimp-floating-sel-anchor floating-sel) ) thumb-layer) ) (define (make-thumb file-name new-height) (let* ( (height-adjust 0) (thumb-img (car (gimp-file-load 1 file-name file-name))) (thumb-layer (car (gimp-image-active-drawable thumb-img))) (old-width (car (gimp-image-width thumb-img))) (old-height (car (gimp-image-height thumb-img))) (wh-ratio (/ old-width old-height)) (new-width (trunc (* new-height wh-ratio))) ) (if (> new-height (trunc new-height)) (set! height-adjust 1) ) (gimp-image-scale thumb-img new-width (+ new-height height-adjust)) (plug-in-sharpen 1 thumb-img thumb-layer 50) ; TODO: Put text (gimp-selection-all thumb-img) (gimp-edit-copy thumb-layer) (gimp-image-delete thumb-img) new-width) ) (define (layer-blend img layer x1 y1 x2 y2) (let* ( (mask 0) ) (gimp-palette-set-foreground '(0 0 0)) (gimp-palette-set-background '(255 255 255)) (if (= (car (gimp-drawable-has-alpha layer)) FALSE) (gimp-layer-add-alpha layer) ) (set! mask (car (gimp-layer-create-mask layer WHITE-MASK))) (gimp-image-add-layer-mask img layer mask) (gimp-blend mask FG-BG-RGB NORMAL-MODE LINEAR 100 0.0 REPEAT-NONE FALSE 3 0.2 x1 y1 x2 y2) (gimp-image-remove-layer-mask img layer APPLY) ) ) (define (layer-soft-border img layer border) (let* ( (width (car (gimp-drawable-width layer))) (height (car (gimp-drawable-height layer))) ) (layer-blend img layer 0 0 border 0) (layer-blend img layer 0 0 0 border) (layer-blend img layer width 0 (- width border) 0) (layer-blend img layer 0 height 0 (- height border)) ) ) (define (thumb-set-offsets img thumb-layers col row width height blend-overlap thumb-space frame-border thumb-height thumb-width-sum) (let* ( (n 0) (thumb-width 0) (new-space 0) (blend-begin 0) (blend-end 0) (thumb-layer 0) (width-offset frame-border) (height-offset (+ frame-border (* (+ thumb-height thumb-space) (- row 1)))) (border-tot (+ (* thumb-space (- col 1)) (* frame-border 2))) ) (if (> col 1) (set! new-space (+ thumb-space (/ (- width (+ thumb-width-sum border-tot)) (- col 1)))) ) (while (<= (set! n (+ n 1)) col) ;(set! width-offset (* (- n 1) 100)) ;(set! height-offset (* (- row 1) 100)) (set! thumb-layer (aref thumb-layers n)) ; Blend thumb layer? (if (and blend-overlap (< thumb-space 0)) (begin ; Leftside blend? (if (and (> n 1) (< new-space 0)) (begin ; Side overlap is usually bigger then thumb-space so ; blend in the middle of the overlap. (set! blend-begin (/ (- (abs new-space) (abs thumb-space)) 2)) (set! blend-end (- (abs new-space) blend-begin)) (layer-blend img thumb-layer blend-begin 0 blend-end 0) )) ; Upperside blend? (if (and (> row 1) (< thumb-space 0)) (begin (layer-blend img thumb-layer 0 0 0 (abs thumb-space)) )) ) (if (and (<= thumb-space 0)) (begin ; TODO: sharp cutoff ))) (gimp-layer-set-offsets thumb-layer width-offset height-offset) (set! thumb-width (car (gimp-drawable-width thumb-layer))) ; TODO add to a html image map. ;(set! html-map-x1 (trunc (- width-offset new-space))) ;(set! html-map-y1 (trunc (- height-offset thumb-space))) ;(set! html-map-x2 (trunc (+ (+ width-offset thumb-width) new-space))) ;(set! html-map-y2 (trunc (+ (+ height-offset thumb-height) thumb-space))) ;(html-append-map n row html-map-x1 html-map-y1 html-map-x2 html-map-y2) (set! width-offset (+ (+ width-offset thumb-width) new-space)) ) ) ) (define (display-image img back-layer) (gimp-layer-set-visible back-layer TRUE) (gimp-image-undo-enable img) (gimp-display-new img) ) (define (make-new-image width height bg-color) (let* ( (img (car (gimp-image-new width height RGB))) (back-layer (car (gimp-layer-new img width height RGB-IMAGE "Back Layer" 100 NORMAL))) ) (gimp-image-undo-disable img) (gimp-selection-none img) (gimp-image-add-layer img back-layer 0) (gimp-palette-set-background bg-color) (gimp-edit-fill back-layer BG-IMAGE-FILL) (gimp-layer-set-visible back-layer FALSE) img) ) (define (calc-height-adj height row) (let* ( (height-adjust1 (- (* height (- row 1)) (trunc (* height (- row 1))))) (height-adjust2 (- (* height row) (trunc (* height row)))) (height-adjust 0) ) ; Calculate height adjust. (if (> height-adjust1 height-adjust2) (set! height-adjust 1) ) height-adjust) ) (define (script-fu-indexgen width height thumb-space blend-overlap frame-border soft-border no-of-rows list-filename bg-color) (let* ( (col 0) (row 1) (thumb-width-sum 0) (file-stream 0) (thumb-filename 0) (thumb-width 0) (leftover-tot 0) (thumb-layer 0) (height-adjust 0) (thumb-nr 0) (old-fg (car (gimp-palette-get-foreground))) (old-bg (car (gimp-palette-get-background))) (img (make-new-image width height bg-color)) (back-layer (car (gimp-image-active-drawable img))) (tspace-tot (* thumb-space (- no-of-rows 1))) (fborder-tot (* frame-border 2)) (thumb-height (/ (- height (+ tspace-tot fborder-tot)) no-of-rows)) (thumb-layers (cons-array 100)) ) (set! file-stream (fopen list-filename "r")) (while (set! thumb-filename (read-line file-stream)) ; Load, resize and copy the thumb image... (if (set! thumb-width (make-thumb thumb-filename thumb-height)) (begin (set! thumb-nr (+ thumb-nr 1)) ; Space positive? (if (> thumb-space 0) (set! leftover-tot (+ thumb-width (+ (* thumb-space col) (* frame-border 2)))) (set! leftover-tot (+ (* thumb-space (- col 1)) (* frame-border 2))) ) ; Too large to fit in row? (if (>= (+ thumb-width-sum leftover-tot) width) (begin ; Set layer offsets for the row (thumb-set-offsets img thumb-layers col row width height blend-overlap thumb-space frame-border thumb-height thumb-width-sum) (gimp-image-merge-visible-layers img CLIP-TO-IMAGE) ; Too many rows to fit in image? (if (>= row no-of-rows) (begin ; Add soft border? (if (> soft-border 0) (begin (set! thumb-layer (aref (cadr (gimp-image-get-layers img)) 0)) (layer-soft-border img thumb-layer soft-border) )) (display-image img back-layer) ; Generate a new image and paste in that (set! img (make-new-image width height bg-color)) (set! back-layer (car (gimp-image-active-drawable img))) (set! height-adjust (calc-height-adj thumb-height 1)) (set! thumb-layer (paste-thumb img thumb-width thumb-height height-adjust)) ; Save the new layer in first array element. (aset thumb-layers (set! col 1) thumb-layer) (set! thumb-width-sum thumb-width) (set! row 1) (set! thumb-nr 1) ) (begin ; Paste in current image, new row (set! height-adjust (calc-height-adj thumb-height (+ row 1))) (set! thumb-layer (paste-thumb img thumb-width thumb-height height-adjust)) ; Save the new layer in first array element. (aset thumb-layers (set! col 1) thumb-layer) (set! thumb-width-sum thumb-width) (set! row (+ row 1)) )) ) (begin ; It fits in row, paste in current image (set! height-adjust (calc-height-adj thumb-height row)) (set! thumb-layer (paste-thumb img thumb-width thumb-height height-adjust)) ; Save the new layer in next array element. (aset thumb-layers (set! col (+ col 1)) thumb-layer) (set! thumb-width-sum (+ thumb-width-sum thumb-width)) )) ) (begin ; Could not load image for some reason )) ) ; Set layer offsets for the last row (thumb-set-offsets img thumb-layers col row width height blend-overlap thumb-space frame-border thumb-height thumb-width-sum) (if (> thumb-nr 1) (gimp-image-merge-visible-layers img CLIP-TO-IMAGE) ) ; Add soft border? (if (> soft-border 0) (begin (set! thumb-layer (aref (cadr (gimp-image-get-layers img)) 0)) (layer-soft-border img thumb-layer soft-border) )) (fclose file-stream) (display-image img back-layer) (gimp-palette-set-foreground old-fg) (gimp-palette-set-background old-bg) ) ) (script-fu-register "script-fu-indexgen" _"/Xtns/Script-Fu/Misc/IndexGen..." "Generate an image of thumbnail images" "Daniel Ryde " "Daniel Ryde" "18 Nov, 2003" "" SF-ADJUSTMENT _"Image width (pixels)" '(800 50 4000 1 10 0 1) SF-ADJUSTMENT _"Image height (pixels)" '(600 50 4000 1 10 0 1) SF-ADJUSTMENT _"Thumb space (pixels)" '(5 -20 20 1 10 0 1) SF-TOGGLE _"Blend overlap" TRUE SF-ADJUSTMENT _"Frame border (pixels)" '(5 -20 20 1 10 0 1) SF-ADJUSTMENT _"Soft border (pixels)" '(0 0 20 1 10 0 1) SF-ADJUSTMENT _"Number of rows" '(6 1 30 1 10 0 0) SF-FILENAME _"Image filelist" "/tmp/test.lst" SF-COLOR _"Background Color" '(255 255 255) )