GIMP Scripts for Faster Sprite Rotation/Creation

Compilation of game resources.

GIMP Scripts for Faster Sprite Rotation/Creation

Postby bamby1983 » Sat Mar 23, 2013 7:21 pm

Since Game Editor hasn't come up with a way by which we can rotate actors easily, we need to create a different animation for each actor angle in the game. For example, if I have a top-down game and want to rotate a player, I need to have a different animation for every angle in which this player would walk, stand, shoot, interact, etc. This is cumbersome graphics design work if you're using a freeware image editing tool like GIMP. To make the process easier and faster, I've developed a few scripts that will perform most of the repetitive tasks automatically. I'll be posting them in this thread and each will most likely have their own separate post. I've included a hyperlinked index in this original post for reference.


Index of GIMP Scripts:

Sprite Operations:
1) Rotate Sequentially - Rotates an image in fixed increments 16 times to form a sprite sheet.
2) Rotate All Layers - Rotates all layers in an images in a single click. The layers rotate around their own center and not around the image center.
3) Array Linear - Creates a horizontal linear array with 10 copies of the original layer. Each copy has its OWN layer, allowing it to be edited to form an animation that can then be used with the preceding script
4) Rotate and Consolidate Sprite Sheet - Creates a massive sprite sheet containing a a 10-frame animation with each frame rotated 16 times in uniform increments

Layer Operations:
1) Resize All Layers - Resizes all the layers in the image to batch the image size and boundaries
2) Autocrop All Layers - Autocrops all layers in an image (removes margins of blank space from each layer)
Last edited by bamby1983 on Fri Apr 19, 2013 12:18 am, edited 12 times in total.
bamby1983
 
Posts: 112
Joined: Tue Jul 31, 2012 11:36 pm
Score: 8 Give a positive score

Re: GIMP Scripts for Faster Sprite Rotation/Creation

Postby bamby1983 » Sat Mar 23, 2013 7:25 pm

Script 1: Rotate Sequentially


Purpose: Rotates an image 16 times and stores this in a newly created image file. The result is a sprite sheet containing the original image rotated in steps of 22.5 degrees 16 times over (360 degrees in all).


Example:

Original Image:
Image

New Image Created by the Script:
Image


Script Naming and Code: The script must be named exactly as follows: rotate-sequentially.scm

Copy the following code into a notepad file named exactly as indicated above. Ensure that the file extension is .scm (NOT .txt). You may need to change the "Save File Type" option to "All Files" while saving this.

Code: Select all
(define (script-fu-rotate-sequentially imgID)
   (let*
      (
         (imgFilename (gimp-image-get-filename imgID)) ; Filename of selected image
         (imgWidth (car (gimp-image-width imgID))) ; Width of selected Image
         (imgHeight (car (gimp-image-height imgID))) ; Height of selected Image
         (img (car (gimp-image-new (* imgWidth 16) imgHeight RGB))) ; Creating a new image
         (sel-float 0) ; Floating selection - drawable actor

         ; Create new layers
         (layer1 (car (gimp-layer-new img imgWidth imgHeight RGBA-IMAGE "1" 100 NORMAL)))
         (layer2 (car (gimp-layer-new img imgWidth imgHeight RGBA-IMAGE "2" 100 NORMAL)))
         (layer3 (car (gimp-layer-new img imgWidth imgHeight RGBA-IMAGE "3" 100 NORMAL)))
         (layer4 (car (gimp-layer-new img imgWidth imgHeight RGBA-IMAGE "4" 100 NORMAL)))
         (layer5 (car (gimp-layer-new img imgWidth imgHeight RGBA-IMAGE "5" 100 NORMAL)))
         (layer6 (car (gimp-layer-new img imgWidth imgHeight RGBA-IMAGE "6" 100 NORMAL)))
         (layer7 (car (gimp-layer-new img imgWidth imgHeight RGBA-IMAGE "7" 100 NORMAL)))
         (layer8 (car (gimp-layer-new img imgWidth imgHeight RGBA-IMAGE "8" 100 NORMAL)))
         (layer9 (car (gimp-layer-new img imgWidth imgHeight RGBA-IMAGE "9" 100 NORMAL)))
         (layer10 (car (gimp-layer-new img imgWidth imgHeight RGBA-IMAGE "10" 100 NORMAL)))
         (layer11 (car (gimp-layer-new img imgWidth imgHeight RGBA-IMAGE "11" 100 NORMAL)))
         (layer12 (car (gimp-layer-new img imgWidth imgHeight RGBA-IMAGE "12" 100 NORMAL)))
         (layer13 (car (gimp-layer-new img imgWidth imgHeight RGBA-IMAGE "13" 100 NORMAL)))
         (layer14 (car (gimp-layer-new img imgWidth imgHeight RGBA-IMAGE "14" 100 NORMAL)))
         (layer15 (car (gimp-layer-new img imgWidth imgHeight RGBA-IMAGE "15" 100 NORMAL)))
         (layer16 (car (gimp-layer-new img imgWidth imgHeight RGBA-IMAGE "16" 100 NORMAL)))
      )
   
   ; Main program code

   ; Layer 1
   (gimp-edit-copy-visible imgID)
   (gimp-image-add-layer img layer1 0)
   (set! sel-float (car (gimp-edit-paste layer1 TRUE)))
   
   
   (gimp-drawable-fill layer1 TRANSPARENT-FILL)
   
   ; Layer 2
   (gimp-image-add-layer img layer2 0)
   (gimp-layer-translate layer2 imgWidth 0)
   (set! sel-float (car (gimp-edit-paste layer2 TRUE))) ; Pasting copied content and recording the drawable area ID
   (gimp-drawable-fill layer2 TRANSPARENT-FILL)
   (gimp-drawable-transform-rotate-default sel-float (* -22.5 (/ 3.1429 180)) TRUE 0 0 TRUE TRANSFORM-RESIZE-CLIP)
   

   ; Layer 3
   (gimp-image-add-layer img layer3 0)
   (gimp-layer-translate layer3 (* imgWidth 2) 0)
   (set! sel-float (car (gimp-edit-paste layer3 TRUE))) ; Pasting copied content and recording the drawable area ID
   (gimp-drawable-fill layer3 TRANSPARENT-FILL)
   (gimp-drawable-transform-rotate-default sel-float (* -45 (/ 3.1429 180)) TRUE 0 0 TRUE TRANSFORM-RESIZE-CLIP)

   ; Layer 4
   (gimp-image-add-layer img layer4 0)
   (gimp-layer-translate layer4 (* imgWidth 3) 0)
   (set! sel-float (car (gimp-edit-paste layer4 TRUE))) ; Pasting copied content and recording the drawable area ID
   (gimp-drawable-fill layer4 TRANSPARENT-FILL)
   (gimp-drawable-transform-rotate-default sel-float (* -67.5 (/ 3.1429 180)) TRUE 0 0 TRUE TRANSFORM-RESIZE-CLIP)

   ; Layer 5
   (gimp-image-add-layer img layer5 0)
   (gimp-layer-translate layer5 (* imgWidth 4) 0)
   (set! sel-float (car (gimp-edit-paste layer5 TRUE))) ; Pasting copied content and recording the drawable area ID
   (gimp-drawable-fill layer5 TRANSPARENT-FILL)
   (gimp-drawable-transform-rotate-default sel-float (* -90 (/ 3.1429 180)) TRUE 0 0 TRUE TRANSFORM-RESIZE-CLIP)

   ; Layer 6
   (gimp-image-add-layer img layer6 0)
   (gimp-layer-translate layer6 (* imgWidth 5) 0)
   (set! sel-float (car (gimp-edit-paste layer6 TRUE))) ; Pasting copied content and recording the drawable area ID
   (gimp-drawable-fill layer6 TRANSPARENT-FILL)
   (gimp-drawable-transform-rotate-default sel-float (* -112.5 (/ 3.1429 180)) TRUE 0 0 TRUE TRANSFORM-RESIZE-CLIP)

   ; Layer 7
   (gimp-image-add-layer img layer7 0)
   (gimp-layer-translate layer7 (* imgWidth 6) 0)
   (set! sel-float (car (gimp-edit-paste layer7 TRUE))) ; Pasting copied content and recording the drawable area ID
   (gimp-drawable-fill layer7 TRANSPARENT-FILL)
   (gimp-drawable-transform-rotate-default sel-float (* -135 (/ 3.1429 180)) TRUE 0 0 TRUE TRANSFORM-RESIZE-CLIP)

   ; Layer 8
   (gimp-image-add-layer img layer8 0)
   (gimp-layer-translate layer8 (* imgWidth 7) 0)
   (set! sel-float (car (gimp-edit-paste layer8 TRUE))) ; Pasting copied content and recording the drawable area ID
   (gimp-drawable-fill layer8 TRANSPARENT-FILL)
   (gimp-drawable-transform-rotate-default sel-float (* -157.5 (/ 3.1429 180)) TRUE 0 0 TRUE TRANSFORM-RESIZE-CLIP)

   ; Layer 9
   (gimp-image-add-layer img layer9 0)
   (gimp-layer-translate layer9 (* imgWidth 8) 0)
   (set! sel-float (car (gimp-edit-paste layer9 TRUE))) ; Pasting copied content and recording the drawable area ID
   (gimp-drawable-fill layer9 TRANSPARENT-FILL)
   (gimp-drawable-transform-rotate-default sel-float (* -180 (/ 3.1429 180)) TRUE 0 0 TRUE TRANSFORM-RESIZE-CLIP)

   ; Layer 10
   (gimp-image-add-layer img layer10 0)
   (gimp-layer-translate layer10 (* imgWidth 9) 0)
   (set! sel-float (car (gimp-edit-paste layer10 TRUE))) ; Pasting copied content and recording the drawable area ID
   (gimp-drawable-fill layer10 TRANSPARENT-FILL)
   (gimp-drawable-transform-rotate-default sel-float (* -202.5 (/ 3.1429 180)) TRUE 0 0 TRUE TRANSFORM-RESIZE-CLIP)

   ; Layer 11
   (gimp-image-add-layer img layer11 0)
   (gimp-layer-translate layer11 (* imgWidth 10) 0)
   (set! sel-float (car (gimp-edit-paste layer11 TRUE))) ; Pasting copied content and recording the drawable area ID
   (gimp-drawable-fill layer11 TRANSPARENT-FILL)
   (gimp-drawable-transform-rotate-default sel-float (* -225 (/ 3.1429 180)) TRUE 0 0 TRUE TRANSFORM-RESIZE-CLIP)

   ; Layer 12
   (gimp-image-add-layer img layer12 0)
   (gimp-layer-translate layer12 (* imgWidth 11) 0)
   (set! sel-float (car (gimp-edit-paste layer12 TRUE))) ; Pasting copied content and recording the drawable area ID
   (gimp-drawable-fill layer12 TRANSPARENT-FILL)
   (gimp-drawable-transform-rotate-default sel-float (* -247.5 (/ 3.1429 180)) TRUE 0 0 TRUE TRANSFORM-RESIZE-CLIP)

   ; Layer 13
   (gimp-image-add-layer img layer13 0)
   (gimp-layer-translate layer13 (* imgWidth 12) 0)
   (set! sel-float (car (gimp-edit-paste layer13 TRUE))) ; Pasting copied content and recording the drawable area ID
   (gimp-drawable-fill layer13 TRANSPARENT-FILL)
   (gimp-drawable-transform-rotate-default sel-float (* -270 (/ 3.1429 180)) TRUE 0 0 TRUE TRANSFORM-RESIZE-CLIP)

   ; Layer 14
   (gimp-image-add-layer img layer14 0)
   (gimp-layer-translate layer14 (* imgWidth 13) 0)
   (set! sel-float (car (gimp-edit-paste layer14 TRUE))) ; Pasting copied content and recording the drawable area ID
   (gimp-drawable-fill layer14 TRANSPARENT-FILL)
   (gimp-drawable-transform-rotate-default sel-float (* -292.5 (/ 3.1429 180)) TRUE 0 0 TRUE TRANSFORM-RESIZE-CLIP)

   ; Layer 15
   (gimp-image-add-layer img layer15 0)
   (gimp-layer-translate layer15 (* imgWidth 14) 0)
   (set! sel-float (car (gimp-edit-paste layer15 TRUE))) ; Pasting copied content and recording the drawable area ID
   (gimp-drawable-fill layer15 TRANSPARENT-FILL)
   (gimp-drawable-transform-rotate-default sel-float (* -315 (/ 3.1429 180)) TRUE 0 0 TRUE TRANSFORM-RESIZE-CLIP)

   ; Layer 16
   (gimp-image-add-layer img layer16 0)
   (gimp-layer-translate layer16 (* imgWidth 15) 0)
   (set! sel-float (car (gimp-edit-paste layer16 TRUE))) ; Pasting copied content and recording the drawable area ID
   (gimp-drawable-fill layer16 TRANSPARENT-FILL)
   (gimp-drawable-transform-rotate-default sel-float (* -337.5 (/ 3.1429 180)) TRUE 0 0 TRUE TRANSFORM-RESIZE-CLIP)

   (gimp-display-new img)
   (gimp-image-clean-all img)
   )
)


(script-fu-register
          "script-fu-rotate-sequentially"             ;Function Name
          "Rotate Sequentially"                       ;Menu Label
          "Rotates an image by 22.5 degrees 16 times and places them in an incremental linear path" ;Description
          "Farsheed Bamboat"                                      ;Author
          ""                                          ;Copyright notice
          "9th March 2013"                                          ;Date Created
          ""                     ;Image type that the script works on
          SF-IMAGE      "Image ID:"         0   ;The image ID
)
        (script-fu-menu-register "script-fu-rotate-sequentially" "<Toolbox>/Script-Fu/Sprite Animation")
bamby1983
 
Posts: 112
Joined: Tue Jul 31, 2012 11:36 pm
Score: 8 Give a positive score

Re: GIMP Scripts for Faster Sprite Rotation/Creation

Postby bamby1983 » Sat Mar 23, 2013 8:13 pm

Script 2: Rotate All Layers


Purpose: Rotates all the layers in an image by the angle specified by the user. Each layer is rotated around it's own center (and not around the image center as is the case with default image rotation in GIMP).


Example:

Original Image:

Sprite Sheet of a Policeman Walking - Each Policeman is a Different Layer:
Image

New Image Created by the Script:
Image


Script Naming and Code: The script must be named exactly as follows: rotate-all-layers.scm

Copy the following code into a notepad file named exactly as indicated above. Ensure that the file extension is .scm (NOT .txt). You may need to change the "Save File Type" option to "All Files" while saving this. You will need to individually select the layer ID for each layer the first time the script runs in a given session. Thereafter, GIMP will store those values for that particular image until you close it and reopen it again.

Code: Select all
(define (script-fu-rotate-all-layers imgID angle layer1 layer2 layer3 layer4 layer5 layer6 layer7 layer8 layer9 layer10)
   
   ; Main program code
   (gimp-drawable-transform-rotate-default layer1 (* angle (/ 3.1429 180)) TRUE 0 0 TRUE TRANSFORM-RESIZE-CLIP)
   (gimp-drawable-transform-rotate-default layer2 (* angle (/ 3.1429 180)) TRUE 0 0 TRUE TRANSFORM-RESIZE-CLIP)
   (gimp-drawable-transform-rotate-default layer3 (* angle (/ 3.1429 180)) TRUE 0 0 TRUE TRANSFORM-RESIZE-CLIP)
   (gimp-drawable-transform-rotate-default layer4 (* angle (/ 3.1429 180)) TRUE 0 0 TRUE TRANSFORM-RESIZE-CLIP)
   (gimp-drawable-transform-rotate-default layer5 (* angle (/ 3.1429 180)) TRUE 0 0 TRUE TRANSFORM-RESIZE-CLIP)
   (gimp-drawable-transform-rotate-default layer6 (* angle (/ 3.1429 180)) TRUE 0 0 TRUE TRANSFORM-RESIZE-CLIP)
   (gimp-drawable-transform-rotate-default layer7 (* angle (/ 3.1429 180)) TRUE 0 0 TRUE TRANSFORM-RESIZE-CLIP)
   (gimp-drawable-transform-rotate-default layer8 (* angle (/ 3.1429 180)) TRUE 0 0 TRUE TRANSFORM-RESIZE-CLIP)
   (gimp-drawable-transform-rotate-default layer9 (* angle (/ 3.1429 180)) TRUE 0 0 TRUE TRANSFORM-RESIZE-CLIP)
   (gimp-drawable-transform-rotate-default layer10 (* angle (/ 3.1429 180)) TRUE 0 0 TRUE TRANSFORM-RESIZE-CLIP)
)


(script-fu-register
          "script-fu-rotate-all-layers"             ;Function Name
          "Rotate All Layers"                       ;Menu Label
          "Rotates all layers of an image in increments of -22.5 degrees. Creates 16 rotated images placed one below the other" ;Description
          "Farsheed Bamboat"                                      ;Author
          ""                                          ;Copyright notice
          "10th March 2013"                                          ;Date Created
          ""                     ;Image type that the script works on
          SF-IMAGE      "Image ID:"         0   ;The image ID
     SF-VALUE   "Angle:"       "-22.5" ;Angle of rotation
     SF-DRAWABLE   "Layer 1"       0   ; Layer 1
     SF-DRAWABLE   "Layer 2"       1   ; Layer 2
     SF-DRAWABLE   "Layer 3"       2   ; Layer 3
     SF-DRAWABLE   "Layer 4"       3   ; Layer 4
     SF-DRAWABLE   "Layer 5"       4   ; Layer 5
     SF-DRAWABLE   "Layer 6"       5   ; Layer 6
     SF-DRAWABLE   "Layer 7"       6   ; Layer 7
     SF-DRAWABLE   "Layer 8"       7   ; Layer 8
     SF-DRAWABLE   "Layer 9"       8   ; Layer 9
     SF-DRAWABLE   "Layer 10"       9   ; Layer 10
)
        (script-fu-menu-register "script-fu-rotate-all-layers" "<Toolbox>/Script-Fu/Sprite Animation")
Last edited by bamby1983 on Sat Mar 23, 2013 8:31 pm, edited 2 times in total.
bamby1983
 
Posts: 112
Joined: Tue Jul 31, 2012 11:36 pm
Score: 8 Give a positive score

Re: GIMP Scripts for Faster Sprite Rotation/Creation

Postby bamby1983 » Sat Mar 23, 2013 8:27 pm

Script 3: Array Linear


Purpose: Creates a horizontal linear array with 10 copies of the original layer. Each copy has its OWN layer, allowing it to be edited to form an animation that can then be used with the preceding script (Rotate All Layers) to automatically create the same animation sequence at different angles.


Example:

Original Image:
Image

New Image Created by the Script - Each Policeman is in a Different Layer:
Image


Script Naming and Code: The script must be named exactly as follows: array-linear.scm

Copy the following code into a notepad file named exactly as indicated above. Ensure that the file extension is .scm (NOT .txt). You may need to change the "Save File Type" option to "All Files" while saving this.

Code: Select all
(define (script-fu-array-linear imgID)
   (let*
      (
         (imgWidth (car (gimp-image-width imgID))) ; Width of selected Image
         (imgHeight (car (gimp-image-height imgID))) ; Height of selected Image
         (img (car (gimp-image-new (* imgWidth 10) imgHeight RGB))) ; Creating a new image
         (sel-float 0) ; Floating selection - drawable actor

         ; Create new layers
         (layer1 (car (gimp-layer-new img imgWidth imgHeight RGBA-IMAGE "1" 100 NORMAL)))
         (layer2 (car (gimp-layer-new img imgWidth imgHeight RGBA-IMAGE "2" 100 NORMAL)))
         (layer3 (car (gimp-layer-new img imgWidth imgHeight RGBA-IMAGE "3" 100 NORMAL)))
         (layer4 (car (gimp-layer-new img imgWidth imgHeight RGBA-IMAGE "4" 100 NORMAL)))
         (layer5 (car (gimp-layer-new img imgWidth imgHeight RGBA-IMAGE "5" 100 NORMAL)))
         (layer6 (car (gimp-layer-new img imgWidth imgHeight RGBA-IMAGE "6" 100 NORMAL)))
         (layer7 (car (gimp-layer-new img imgWidth imgHeight RGBA-IMAGE "7" 100 NORMAL)))
         (layer8 (car (gimp-layer-new img imgWidth imgHeight RGBA-IMAGE "8" 100 NORMAL)))
         (layer9 (car (gimp-layer-new img imgWidth imgHeight RGBA-IMAGE "9" 100 NORMAL)))
         (layer10 (car (gimp-layer-new img imgWidth imgHeight RGBA-IMAGE "10" 100 NORMAL)))
      )
   
   ; Main program code

   ; Layer 1
   (gimp-edit-copy-visible imgID)
   (gimp-image-add-layer img layer1 0)
   (set! sel-float (car (gimp-edit-paste layer1 TRUE)))
   (gimp-drawable-fill layer1 TRANSPARENT-FILL)
   
   ; Layer 2
   (gimp-image-add-layer img layer2 0)
   (gimp-layer-translate layer2 imgWidth 0)
   (set! sel-float (car (gimp-edit-paste layer2 TRUE))) ; Pasting copied content and recording the drawable area ID
   (gimp-drawable-fill layer2 TRANSPARENT-FILL)
   

   ; Layer 3
   (gimp-image-add-layer img layer3 0)
   (gimp-layer-translate layer3 (* imgWidth 2) 0)
   (set! sel-float (car (gimp-edit-paste layer3 TRUE))) ; Pasting copied content and recording the drawable area ID
   (gimp-drawable-fill layer3 TRANSPARENT-FILL)

   ; Layer 4
   (gimp-image-add-layer img layer4 0)
   (gimp-layer-translate layer4 (* imgWidth 3) 0)
   (set! sel-float (car (gimp-edit-paste layer4 TRUE))) ; Pasting copied content and recording the drawable area ID
   (gimp-drawable-fill layer4 TRANSPARENT-FILL)

   ; Layer 5
   (gimp-image-add-layer img layer5 0)
   (gimp-layer-translate layer5 (* imgWidth 4) 0)
   (set! sel-float (car (gimp-edit-paste layer5 TRUE))) ; Pasting copied content and recording the drawable area ID
   (gimp-drawable-fill layer5 TRANSPARENT-FILL)

   ; Layer 6
   (gimp-image-add-layer img layer6 0)
   (gimp-layer-translate layer6 (* imgWidth 5) 0)
   (set! sel-float (car (gimp-edit-paste layer6 TRUE))) ; Pasting copied content and recording the drawable area ID
   (gimp-drawable-fill layer6 TRANSPARENT-FILL)

   ; Layer 7
   (gimp-image-add-layer img layer7 0)
   (gimp-layer-translate layer7 (* imgWidth 6) 0)
   (set! sel-float (car (gimp-edit-paste layer7 TRUE))) ; Pasting copied content and recording the drawable area ID
   (gimp-drawable-fill layer7 TRANSPARENT-FILL)

   ; Layer 8
   (gimp-image-add-layer img layer8 0)
   (gimp-layer-translate layer8 (* imgWidth 7) 0)
   (set! sel-float (car (gimp-edit-paste layer8 TRUE))) ; Pasting copied content and recording the drawable area ID
   (gimp-drawable-fill layer8 TRANSPARENT-FILL)

   ; Layer 9
   (gimp-image-add-layer img layer9 0)
   (gimp-layer-translate layer9 (* imgWidth 8) 0)
   (set! sel-float (car (gimp-edit-paste layer9 TRUE))) ; Pasting copied content and recording the drawable area ID
   (gimp-drawable-fill layer9 TRANSPARENT-FILL)

   ; Layer 10
   (gimp-image-add-layer img layer10 0)
   (gimp-layer-translate layer10 (* imgWidth 9) 0)
   (set! sel-float (car (gimp-edit-paste layer10 TRUE))) ; Pasting copied content and recording the drawable area ID
   (gimp-drawable-fill layer10 TRANSPARENT-FILL)

   (gimp-display-new img)
   (gimp-image-clean-all img)
   )
)


(script-fu-register
          "script-fu-array-linear"             ;Function Name
          "Array Linear"                       ;Menu Label
          "Creates a linear array with each clone in a new layer" ;Description
          "Farsheed Bamboat"                                      ;Author
          ""                                          ;Copyright notice
          "16th March 2013"                                          ;Date Created
          ""                     ;Image type that the script works on
          SF-IMAGE      "Image ID:"         0   ;The image ID
     SF-DRAWABLE   "Layer 1"           0   ;Original Layer
)
        (script-fu-menu-register "script-fu-array-linear" "<Toolbox>/Script-Fu/Sprite Animation")
bamby1983
 
Posts: 112
Joined: Tue Jul 31, 2012 11:36 pm
Score: 8 Give a positive score

Re: GIMP Scripts for Faster Sprite Rotation/Creation

Postby bamby1983 » Tue Mar 26, 2013 10:49 pm

Script 4: Rotate and Consolidate Sprite Sheet

Purpose: Creates a massive sprite sheet containing a a 10-frame animation with each frame rotated 16 times in uniform increments. There are 10 columns (1 per animation frame) and 16 rows (1 for each rotated angle), totaling 160 frames in all. Every image in the sprite sheet is a separate layer and is rotated around the center of the original layer it was copied from.


Example:

Original Image:
Image

New Image Created by the Script - Each row is the same animation as the earlier row rotated by an additional 22.5 degrees:
Image


Script Naming and Code: The script must be named exactly as follows: rotate-and-consolidate-sprite-sheet.scm

The script code is way too big to post in this thread (it exceed the max characters threshold). Since ".scm" files are not allowed as attachments, I've zipped the file containing the script and attached it along with this post.
Attachments
rotate-and-consolidate-sprite-sheet.zip
(4.42 KiB) Downloaded 248 times
Last edited by bamby1983 on Wed Mar 27, 2013 5:10 pm, edited 2 times in total.
bamby1983
 
Posts: 112
Joined: Tue Jul 31, 2012 11:36 pm
Score: 8 Give a positive score

Re: GIMP Scripts for Faster Sprite Rotation/Creation

Postby lcl » Tue Mar 26, 2013 11:07 pm

Just put your code into a zip folder. =)

Why there is an empty square in the sprite sheet, by the way?
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: GIMP Scripts for Faster Sprite Rotation/Creation

Postby bamby1983 » Wed Mar 27, 2013 5:12 pm

lcl wrote:Just put your code into a zip folder. =)

Thanks! That worked!

lcl wrote:Why there is an empty square in the sprite sheet, by the way?

Oops, one of the lines in the code had a typo. Thanks for being so observant and pointing it out. I've fixed it now. :)
bamby1983
 
Posts: 112
Joined: Tue Jul 31, 2012 11:36 pm
Score: 8 Give a positive score

Re: GIMP Scripts for Faster Sprite Rotation/Creation

Postby Jagmaster » Tue Apr 16, 2013 5:57 pm

Thanks, these will be quite useful!

One plugin I'd find very useful is one that could autocrop all layers in an image. I often work with large image sequences, and it's very tedious to autocrop each and every layer. :roll:
I was wondering if this would be very easy to do? If I knew script-fu I'd probably do it myself xD
User avatar
Jagmaster
 
Posts: 875
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 82 Give a positive score

Re: GIMP Scripts for Faster Sprite Rotation/Creation

Postby bamby1983 » Wed Apr 17, 2013 9:30 pm

Here's the script to resize all layers to the image size as requested.

Script 5: Resize All Layers

Purpose: Resizes all layers in the GIMP image (.xcf file) to match the image size and boundaries

Script Naming and Code: The script must be named exactly as follows: resize-all-layers.scm

Code: Select all
(define (script-fu-resize-all-layers imgID)
   (let*
      (
         (layers_info (gimp-image-get-layers imgID))
         (layers_num (car layers_info))
              (layers_array (cadr layers_info))
         (i 0)
      )

   ; Main program code
   (while (< i layers_num)
      (let
         (
            (drawable (aref layers_array i))
         )
      (gimp-layer-resize-to-image-size drawable)
      )
      (set! i (+ i 1))
        )

   )   
)


(script-fu-register
          "script-fu-resize-all-layers"             ;Function Name
          "Resize All Layers"                       ;Menu Label
          "Resizes all layers in an image to the image size"  ;Description
          "Farsheed Bamboat"                        ;Author
          ""                                        ;Copyright notice
          "17th April 2013"                         ;Date Created
          ""                               ;Image type that the script works on
          SF-IMAGE      "Image ID:"         0       ;The image ID
)
        (script-fu-menu-register "script-fu-resize-all-layers" "<Toolbox>/Script-Fu/Layer Operations")


The attached ZIP file contains the .scm file and a sample .xcf file with 3 layers in case you want to test this on your system. The .xcf file is not required for this script to work.
Attachments
resize-all-layers.zip
(1.7 KiB) Downloaded 256 times
bamby1983
 
Posts: 112
Joined: Tue Jul 31, 2012 11:36 pm
Score: 8 Give a positive score

Re: GIMP Scripts for Faster Sprite Rotation/Creation

Postby Jagmaster » Thu Apr 18, 2013 1:01 am

Thank you! That's a really handy script, and I'll make use of it. :) I shall give you a point!

I'm afraid it only solves half of my problem though.

I really wasn't too clear in my previous post, sorry about that. I really need one that will do the "autocrop layer" operation once for every layer in the image. That way all the layers are autocropped individually. Like so

I deal with animation loops that have hundreds of frames. I have to autocrop each layer, and then run the "fit canvas to layers" operation so that way the canvas is fitting the animation the most efficient way possible without cutting off any frames. Your new script is handy for the last part, where I resize the layers to the new image size.

I hope I'm making a little sense at least. Like I said before I would figure it out myself, if only I knew script-fu. :lol:
User avatar
Jagmaster
 
Posts: 875
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 82 Give a positive score

Re: GIMP Scripts for Faster Sprite Rotation/Creation

Postby bamby1983 » Fri Apr 19, 2013 12:17 am

Here's the script to autocrop all layers as requested.

Script 6: Autocrop All Layers

Purpose: Autocrops all layers in the GIMP .xcf file (removes the transparent margin space)

Script Naming and Code: The script must be named exactly as follows: autocrop-all-layers.scm

Code: Select all
(define (script-fu-autocrop-all-layers imgID)
   (let*
      (
         (layers_info (gimp-image-get-layers imgID))
         (layers_num (car layers_info))
              (layers_array (cadr layers_info))
         (i 0)
      )

   ; Main program code
   (while (< i layers_num)
      (let
         (
            (drawable (aref layers_array i))
         )
      (gimp-image-set-active-layer imgID drawable)
      (plug-in-autocrop-layer RUN-NONINTERACTIVE imgID drawable)
      )
      (set! i (+ i 1))
        )

   )   
)


(script-fu-register
          "script-fu-autocrop-all-layers"             ;Function Name
          "Autocrop All Layers"                       ;Menu Label
          "Autocrops all layers in an image"  ;Description
          "Farsheed Bamboat"                        ;Author
          ""                                        ;Copyright notice
          "18th April 2013"                         ;Date Created
          ""                               ;Image type that the script works on
          SF-IMAGE      "Image ID:"         0       ;The image ID
)
        (script-fu-menu-register "script-fu-autocrop-all-layers" "<Toolbox>/Script-Fu/Layer Operations")



The attached ZIP file contains the .scm file and a sample .xcf file with 3 layers in case you want to test this on your system. The .xcf file is not required for this script to work.
Attachments
autocrop-all-layers.zip
(1.48 KiB) Downloaded 247 times
bamby1983
 
Posts: 112
Joined: Tue Jul 31, 2012 11:36 pm
Score: 8 Give a positive score

Re: GIMP Scripts for Faster Sprite Rotation/Creation

Postby Jagmaster » Fri Apr 19, 2013 12:35 am

This is absolutely fantastic! Thank you so much, you have no idea how much this helps! :mrgreen:
score ++
User avatar
Jagmaster
 
Posts: 875
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 82 Give a positive score

Re: GIMP Scripts for Faster Sprite Rotation/Creation

Postby bamby1983 » Fri Apr 19, 2013 2:07 am

I'm glad I could be of assistance. :)
bamby1983
 
Posts: 112
Joined: Tue Jul 31, 2012 11:36 pm
Score: 8 Give a positive score

Re: GIMP Scripts for Faster Sprite Rotation/Creation

Postby GEuser » Fri Apr 19, 2013 3:54 pm

Jagmaster wrote:This is absolutely fantastic! Thank you so much, you have no idea how much this helps! :mrgreen:
score ++

I second that!

Thanks bamby, this saves a HUGE amount of time faffing about with layers manually.
GEuser
 
Posts: 204
Joined: Thu Jan 05, 2012 3:08 pm
Score: 19 Give a positive score


Return to Resources

Who is online

Users browsing this forum: No registered users and 1 guest

cron