Raoul Boenisch <[EMAIL PROTECTED]> writes:

> You think so? Isn't it an all day task? I draw images by hand to
> form an animation and then scan them all with my fax-device which
> has an automagic page feeder. That's comfortable. But it is not very
> comfortable to load every image into a layer by hand with gimp :(

Here is a little script-fu that will handle such kind of things. It
takes an filename as argument.
The given file must contain a list of the images you want to load, the
only problem is, that the filenames must be complete, so you can have
relative filenames. An example:

You have a directory full of .png files you want to merge, so you 'cd'
to that directory and enter:

$ find . -name "*.png" -type f -and -printf "`pwd`/%P\n" > image.list
$ cat image.list

Now you can start Gimp and load 'image.list' with
"<Xtns>/Script-fu/Misc/Load Sequenze"  

You should get now an new image, containing all the mentioned images
as layers.



;; ---- snip -----------

;; Load a sequenze of images
;; Copyright (C) 2000 Ingo Ruhnke <[EMAIL PROTECTED]>
;; 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
;; 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.

(define else #t)
(define have-eof #f)

(define (vector->list vector)
  (define (vector->list-helper vector index)
    (cond ((< index (length vector))
           (cons (aref vector index)
                 (vector->list-helper vector (+ index 1))))
  (vector->list-helper vector 0))

(define (my-getline filehandle)
  (let ((character (fread 1 filehandle)))
    (cond ((equal? character "\n")
          ((equal? character ())
           (set! have-eof #t)
           (string-append character (my-getline filehandle))))))

(define (my-readfile filehandle)
  (cond ((not have-eof)
         (let ((line (my-getline filehandle)))
           (cond ((> (string-length line) 0)
                  (cons line
                        (my-readfile filehandle)))
                  (my-readfile filehandle)))))

(define (load-images images)
  (map (lambda (filename) (car (gimp-file-load 0 filename filename)))

(define (copy-drawables-to new-image drawables)
  (cond ((not (null? drawables))
         (let* ((drawable (car drawables))
                (width (car (gimp-drawable-width drawable)))
                (height (car (gimp-drawable-height drawable))))
           (gimp-edit-copy drawable)
           (let ((new-layer (car (gimp-layer-new new-image width height RGB 
                                                 (car (gimp-image-get-filename 
                                                       (car (gimp-drawable-image 
                                                 100 0))))
             (gimp-layer-add-alpha new-layer)
             (gimp-floating-sel-anchor (car (gimp-edit-paste new-layer 0)))
             (gimp-image-add-layer new-image new-layer 0))))))
(define (copy-image-to new-image other-image)
  (copy-drawables-to new-image
                     (vector->list (cadr (gimp-image-get-layers other-image)))))

(define (copy-all-images-to new-image images)
  (cond ((not (null? images))
         (copy-image-to new-image (car images))
         (copy-all-images-to new-image (cdr images)))))

(define (script-fu-load-sequenze filename)
  (let* ((filehandle (fopen filename))
         (filecontent (reverse (my-readfile filehandle)))
         (images (load-images filecontent))
         (width  (apply max (map (lambda (x) (car (gimp-image-width x)))
         (height (apply max (map (lambda (x) (car (gimp-image-height x)))
    (print width)
    (print height)
    (let ((new-image (car (gimp-image-new width height RGB))))
      (copy-all-images-to new-image images)
      (gimp-display-new new-image))))

(script-fu-register "script-fu-load-sequenze"
                    "<Toolbox>/Xtns/Script-Fu/Misc/Load sequenze."
                    "Load a sequenze of images"
                    "Ingo Ruhnke"
                    "1999, Ingo Ruhnke"
                    "Fri Mar  3 16:00:13 2000"
                    "RGB RGBA"
                    SF-FILENAME "Directory:" "")
;; EOF ;;

ICQ: 59461927                                    http://pingus.seul.org | 
Ingo Ruhnke <[EMAIL PROTECTED]>             http://home.pages.de/~grumbel/ |

Reply via email to