Quoting Brian Vanderburg II <[EMAIL PROTECTED]>:

Out of need I created a script and finally got it working even on 2.3.18.

Normally an animation is either done as one layer for each frame or
using GIMP Animation Package one file per frame.  With the first
method, it is not possible to have multiple layers per frame since a
layer is a frame.  With the second, multiple files must be kept.  While
GAP is good, for simple animations it would be easier to just store
each frame in one image side by side.

I would propose you consider modifying your script to handle the more generic case of multiple rows of tiles. Your dialog would need an additional entry for "Tile Height" and could provide a "Use image height (ie, Single Row)" checkbox for convenience.

Gimp-user mailing list
I've made those changes and more. It supports frame width (0 for image width), frame height (0 for image height) frame count (0 for rows * col) in case there are 3x3 rows but only say 7 frames, and direction (left to right then top to bottom or top to bottom then left to right).

It may only work with gimp 2.3+ since it uses the function 'floor' and I don't know if gimp 2.2 has it.

I have attached it here if anyone is interested and I will try and submit it to the register.
;; tile2anim.scm -*-scheme-*-
;; Converts a tiled animation to a layered animation
;; A tiled animation is one where each frame of the animation
;; is tiled across the image horizontally.  For example,
;; a 48x48 30 frame animation would be an image with the
;; size 1440x48.  Frame 1 is at (0,0)-(47,47), 2 at (48,0)-(95,47)
;; and so on
;; Version 1.2
;; Copyright (C) 2007 by Brian Vanderburg II
;; 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

; Internal function to create the layered animation
(define (script-fu-tile2anim img drw frameWidth frameHeight frameCount 

    ; get image information
    (set! theWidth (car (gimp-image-width img)))
    (set! theHeight (car (gimp-image-height img)))
    ; create new image and layer
    (set! theImage (car (gimp-image-new theWidth theHeight RGB)))
    (set! theLayer (car (gimp-layer-new theImage theWidth theHeight RGBA-IMAGE 
    (gimp-image-add-layer theImage theLayer 0)
    (gimp-drawable-fill theLayer TRANSPARENT-FILL)
    ; copy visible portion of image
    (gimp-selection-none img)
    (if (= (car (gimp-edit-copy-visible img)) TRUE)
        (gimp-rect-select theImage 0 0 theWidth theHeight CHANNEL-OP-REPLACE 0 
        (gimp-floating-sel-anchor (car (gimp-edit-paste theLayer FALSE)))
    ; frame width
    (if (= frameWidth 0) (set! frameWidth theWidth) )
    ; frame height
    (if (= frameHeight 0) (set! frameHeight theHeight) )
    ; number of columns and rows
    (set! theCols (floor (/ theWidth frameWidth)) )
    (set! theRows (floor (/ theHeight frameHeight)) )
    ; number of frames
    (if (= frameCount 0)
      (set! frameCount (* theCols theRows))
      (if (> frameCount (* theCols theRows)) (set! frameCount (* theCols 
    ; process frames
    (set! framePos 0)
    (set! theCol 0)
    (set! theRow 0)
    (while (< framePos frameCount)
      ; create new layer and add it to image
      (set! tmpLayer (car (gimp-layer-new theImage frameWidth frameHeight 
      (gimp-image-add-layer theImage tmpLayer -1)
      (gimp-drawable-fill tmpLayer TRANSPARENT-FILL)
      ; copy
      (gimp-rect-select theImage (* theCol frameWidth) (* theRow frameHeight) 
frameWidth frameHeight CHANNEL-OP-REPLACE 0 0)
      (if (= (car (gimp-edit-copy theLayer)) TRUE)
          (gimp-rect-select theImage 0 0 frameWidth theHeight 
          (gimp-floating-sel-anchor (car (gimp-edit-paste tmpLayer FALSE) ) )
      (gimp-selection-none theImage)
      ; next frame
      (set! framePos (+ framePos 1))
      ; direction (0 = left to right first, else top to bottom first)
      (if (= frameDirection 0)
          (set! theCol (+ theCol 1) )
          (if (>= theCol theCols)
              (set! theCol 0)
              (set! theRow (+ theRow 1) )
          (set! theRow (+ theRow 1) )
          (if (>= theRow theRows)
              (set! theRow 0)
              (set! theCol (+ theCol 1) )
    ; Remove old layer
    (gimp-image-remove-layer theImage theLayer)
    ; set correct image size
    (gimp-image-resize theImage frameWidth frameHeight 0 0)
    ; show image
    (gimp-display-new theImage)
) ; script-fu-tile2anim

(script-fu-register "script-fu-tile2anim"
                    _"Converts a tile of frames to a layered animation."
                    "Brian Vanderburg II <[EMAIL PROTECTED]>"
                    "Brian Vanderburg II"
                    "August 2007"
                    "RGB*, INDEXED*, GRAY*"
                    SF-IMAGE       "Image"            0
                    SF-DRAWABLE    "Layer (unused)"   0

                    SF-ADJUSTMENT _"Frame Width (0 for Image Width)"   '(48 0 
20000 1 10)
                    SF-ADJUSTMENT _"Frame Height (0 for Image Height)"   '(48 0 
20000 1 10 0 0)
                    SF-ADJUSTMENT _"Frame Count (0 for Auto)"   '(0 0 2000000 1 
10 0 0)
                    SF-OPTION _"Direction" '(_"Left to Right" _"Top to Bottom") 
(script-fu-menu-register "script-fu-tile2anim"
                         ; _"<Image>/Script-Fu/Animators")
Gimp-user mailing list

Reply via email to