I've just finished a script-fu that splits an RGB*-image into pieces and
saves them them to gifs. I needed this script to produce buttons for a
web-site. If you create web-gfx with gimp you often have many icons,
buttons or whatever of one type. So its easier to create and manipulate
all elements in ONE image. My problem was, that I had to cut-out about
20 elements, pixel-accurate, and save them to gifs. And I had to repeat
this procedure after every little change (e.g. color-change).

So I wrote this little script-fu, which cuts a large image in a number of rows
and saves these to gifs. It works on RGB*-pictures only (it produces black
images when working with indexed-mode, don't ask me why). It  takes the

    yoffset             y-pixel-offset (where the first row starts)
    yheight             height off the rows
    ydelta              difference between two rows (usually = yheight)
    ypieceoffset        you can skip whole rows with this parameter, e.g.
                        start with row 2).
    ypieces             number of rows to cut
    savepath            path and name of images, if you cut 8 images and
                        set savepath to c:\tmp\image it will result in in
                        c:\tmp\image0.gif, c:\tmp\image1.gif ......

So, after offering my script I must warn you. There is a BIG PROBLEM with it.
It crashes gimp if the amount of ypieces gets to high. I tried to deallocate/free/
delete the used layers, but i didn't work. Freeing the image doesn't work too...

So, maybe there is some script-fu-master here to help me ????
Now the script:

------ snip --------

; split-image.scm
; 03/16/2000

(define (script-fu-selection-split-image image drawable yoffset yheight ydelta 
ypiecesoffset ypieces
( let* (
(ystart yoffset)
(iwidth (car (gimp-image-width image)))
(iheight (car (gimp-image-height image)))
(draw-type (car (gimp-drawable-type-with-alpha drawable)))
(image-type (car (gimp-image-base-type image)))
(old-bg (car (gimp-palette-get-background)))
(savename "")
(postfix 0)
(ypiecescount 0)

(gimp-image-undo-disable image)

(set! ypiecescount ypiecesoffset)
(set! ystart (+ ystart (* ypiecescount ydelta)))

(while (< ypiecescount ypieces)
   (gimp-rect-select image 0 ystart iwidth yheight REPLACE FALSE 0)

    (gimp-edit-copy drawable)

    (set! new-image (car (gimp-image-new iwidth yheight image-type)))
    (set! new-draw (car (gimp-layer-new new-image iwidth yheight draw-type "Selection" 
100 NORMAL)))
    (gimp-image-add-layer new-image new-draw 0)
    (gimp-drawable-fill new-draw BG-IMAGE-FILL)

    (let (
   (floating-sel (car (gimp-edit-paste new-draw FALSE)))
     (gimp-floating-sel-anchor floating-sel)

    ; (set! new-display (car (gimp-display-new new-image)))
    (set! savename (string-append savepath (number->string postfix)))
    (set! savename (string-append savename ".gif"))
    (set! postfix (+ postfix 1))
    ; (gimp-message savename)

    (gimp-convert-indexed new-image 3 0 256 FALSE FALSE "")
    (gimp-file-save 1 new-image new-draw savename savename)

    ; (gimp-image-delete new-image)
    ; (gimp-display-delete (new-display))   ; does NOT WORK, grrrrrrrr

    (gimp-image-set-active-layer image drawable)
    (set! ystart (+ ystart ydelta))
    (set! ypiecescount (+ ypiecescount 1))
    ; (set! ystart iheight)

  (gimp-image-undo-enable image)
  (gimp-palette-set-background old-bg)


    "<Image>/Script-Fu/Selection/Split An Image"
    "Split an image to rows and save
    the images as indexed gif's works
    on flattened RGB Images-Only"
    "Christian Schlange <[EMAIL PROTECTED]>"
    "Christian Schlange"
    "RGB* GRAY*"
    SF-IMAGE "Image" 0
    SF-DRAWABLE "Drawable" 0
    SF-VALUE "yoffset:" "1"
    SF-VALUE "yheight:" "19"
    SF-VALUE "ydelta:" "22"
    SF-VALUE "ypieceoffset:" "0"
    SF-VALUE "ypieces:" "8"
    SF-FILENAME "filename (w/o ext): " ""

Reply via email to