Create layered animation from a tiled animation.
This discussion is connected to the gimp-user-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.
This is a read-only list on gimpusers.com so this discussion thread is read-only, too.
Create layered animation from a tiled animation. | Brian Vanderburg II | 30 Aug 20:06 |
Create layered animation from a tiled animation. | Scott Bicknell | 30 Aug 20:30 |
Create layered animation from a tiled animation. | saulgoode@flashingtwelve.brickfilms.com | 30 Aug 22:02 |
Create layered animation from a tiled animation. | Brian Vanderburg II | 11 Sep 22:48 |
Create layered animation from a tiled animation.
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.
This script makes it where the animation is actually in a single file, each frame tiled horizontally across. The script itself simply converts the tiled animation into layers. For example, a 32x32 animation with 10 frames would be created as a 320x32 image, and the frames would be at (0,0)-(31,31),(32,0)-(63,31),etc where the left most part is the first frame. The animation can have layers. It is possible to have a certain item appear on each frame simply by creating it in one area and tiling it across with the Map->Tile plugin. When desired to export the animation, this script will simply copy the visible part of the image and cut it based on the frame size into layers automatically.
I don't know where to send this script or if it would be useful to anyone else, so it is included in this email as an attachment.
;; 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
;; 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Internal function to create the layered animation (define (script-fu-tile2anim img drw frameWidth)
(let*
(
(theWidth)
(theHeight)
(theImage)
(theLayer)
(framePos)
(frameCount)
(tmpLayer)
)
; 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 "TMP" 100 NORMAL-MODE)))
(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)
(begin
(gimp-rect-select theImage 0 0 theWidth theHeight CHANNEL-OP-REPLACE 0 0)
(gimp-floating-sel-anchor (car (gimp-edit-paste theLayer FALSE)))
)
)
; number of frames
; TODO: Make sure number is rounded down (4.7 = 4 frames)
(set! frameCount (/ theWidth frameWidth))
; process frames
(set! framePos 0)
(while (< framePos frameCount)
; create new layer and add it to image
(set! tmpLayer (car (gimp-layer-new theImage frameWidth theHeight RGBA-IMAGE "Layer" 100 NORMAL-MODE)))
(gimp-image-add-layer theImage tmpLayer -1)
(gimp-drawable-fill tmpLayer TRANSPARENT-FILL)
; copy
(gimp-rect-select theImage (* framePos frameWidth) 0 frameWidth theHeight CHANNEL-OP-REPLACE 0 0)
(if (= (car (gimp-edit-copy theLayer)) TRUE)
(begin
(gimp-rect-select theImage 0 0 frameWidth theHeight CHANNEL-OP-REPLACE 0 0)
(gimp-floating-sel-anchor (car (gimp-edit-paste tmpLayer FALSE) ) )
)
)
(gimp-selection-none theImage)
; next frame
(set! framePos (+ framePos 1))
)
; Remove old layer
(gimp-image-remove-layer theImage theLayer)
; set correct image size
(gimp-image-resize theImage frameWidth theHeight 0 0)
; show image
(gimp-display-new theImage)
)
) ; script-fu-tile2anim
(script-fu-register "script-fu-tile2anim"
_"_Tiles2Animation..."
_"Converts a horizontal tile of frames to a layered animation."
"Brian Vanderburg II "
"Brian Vanderburg II"
"August 2007"
"RGB*, INDEXED*, GRAY*"
SF-IMAGE "Image" 0
SF-DRAWABLE "Drawable" 0
SF-ADJUSTMENT _"Frame Width" '(48 1 20000 1 10 0 0) )
(script-fu-menu-register "script-fu-tile2anim"
; _"/Script-Fu/Animators")
_"/Filters/Animation")
Create layered animation from a tiled animation.
On Thursday, August 30, 2007 11:06:21 am Brian Vanderburg II wrote:
Out of need I created a script and finally got it working even on 2.3.18.
...
I don't know where to send this script or if it would be useful to anyone else, so it is included in this email as an attachment.
Create layered animation from a tiled animation.
Quoting Brian Vanderburg II :
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.
Create layered animation from a tiled animation.
saulgoode@flashingtwelve.brickfilms.com wrote:
Quoting Brian Vanderburg II :
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.