ofn3-layer-tiles

# ofn-layer-tiles

This script is used to split a layer into individual tile layers (rectangles all of same height and width), or to position/join layers of same width and height to form a single continuous image.

## Splitting

Splitting can be specified either as a number of columns and rows or as the width and height of the individual tiles.

The script is called via the menu entries:

- `Layer > Tiles > Split layer given width and height`
- `Layer > Tiles > Split layer given rows and columns`

### Parameters

- `Rows`, `Columns`: the number of tiles to create on the height and the width of the layer. The layer size in pixels should be an integer multiple of these values (in other words, you cannot have partial tiles). If necessary, resize the layer first.
- `Width`, `Height`: the width and height (in pixels) of the tiles. The layer size in pixels should be an integer multiple of these values (in other words, you cannot have partial tiles). If necessary, resize the layer first.
- `Name pattern`: a pattern that defines the name of the saved tiles (see below)7
- `Rows/Columns order`: how the layers are generated.

  - `Rows first`: the first consecutive items in the generated layers stack come from the same row:

          1 2 3
          4 5 6

  - `Columns first`: the first consecutive items in the generated layers stack come from the same column:

          1 3 5
          2 4 6

- `Split result`:
  - `Keep In place`: the tile layers are kept above their source position in the initial layer.
  - `Superimpose`: the tile layers are all given an offset of 0,0 (this moves them all to the top-left corner). This is useful if all the tiles should become an animation.
  - `Superimpose and shrink`: like the above, and the image canvas is shrunk to fit the resulting layers (as well as any existing layers that are not part of the split)

### Tile name pattern

The tile name pattern specifies how the tile layers are named using specific tile data. In the pattern, names in braces are replaced by the values of these data for the tile. For instance, a pattern of `Tile-{column1}-{row1}.png` will produce the name `Tile-2-3.png` for the 2nd tile on the 3rd row.

The names of some numeric values have two forms: one ending in `0` and one ending in `1`. The one ending in `0` starts at `0` (as computers count), while the one in `1` starts at `1` (as humans count).

The available values are:

- `layerName`: the name of the source layer
- `layerRoot`: the name of the source layer, without any file extension
- `layerExt`: the file extension in the name of the source layer (including the leading dot)
- `rows`: the number of rows
- `columns`: the number of columns
- `count`: the total number of tiles (rows * columns)
- `width`: the width of the tiles
- `height`: the height of the tiles
- `row0`,`row1`: the row number of the tile
- `column0`,`column1`: the column number of the tile
- `tileCR0`, `tileCR1`, `tileRC0`, `tileRC1`: the sequence number of the tile. The `tileRC` value increments the columns before the rows, and the `tileCR` values increments the rows before the columns.

#### Hints:

The name pattern is actually directly used as a Python format specification, so modifiers can be used. The most useful modifier for numbers is the ability to define a minimal length with zero-padding. This is done by adding `:0Nd` to the variable name in the braces, for instance `{row1:03d}` will insert the row number on at least three digits, with zeroes added to the left if necessary: `001`, `013`, `099`, `100`.

## Joining

This script is called via the menu entry: `Layer > Tiles > Join tiles`

The script works on the selected layers, which means it is disabled in the menus if there aren’t at least two layers selected. You can select all layers by using `Ctrl-A` in the `Layers` list.

The script will not accept groups, but will accept their contents.

The final result replaces the bottom-most layer (and so has the same parent as this layer)

### Parameters

- `Row/Columns`: how the number of rows and columns is determined:

  - `Rows given, compute columns` and `Columns given, compute rows`: the script uses the number in the next field as a count of rows and columns, and deduces the other count by dividing the total number of layers.
  - `Parse tile names`: the script looks for two groups of digits in the names of the tile layers (see a more complete explanation below)

  Your total number of layers should be an integer multiple of the specified number of columns or rows. If necessary, complement the existing layers with other layers (transparent, filled, or copies of other layers, as you see fit).

- `Rows or columns` the number of rows or columns, depending on what is specified in the previous field. This is ignored if you use the `Parse tile names` option

- `Rows/Columns order`: this field has two different (and somewhat unrelated) meanings:
  - When not using `Parse tile names`, this describes the order of the tiles in the input stack. `Rows first` then means that the first layers will belong to the same row.
  - When using `Parse tile names`, this indicates if the first group of digits refers to rows or to columns.
- `Stack order`: this indicates if the first tile is at the bottom or the top of the layer stack. In animations, the first frame is at the bottom.
- `Merge`: in the final result, the tiles are kept distinct, or flattened to a single layer.
- `Resize image`: the image is resized to fit the tiles and any other layer or group not part of the input layers.

#### Guessing the rows and columns

If the files are named so that they contain at least two identifiable groups of digits, then the last two groups are considered to be rows and columns numbers, and the numbers of rows and columns are determined by the difference between the smallest and biggest values. The following naming schemes are for instance valid:

- `Tile-01-01.png`
- `Tile-01-01nodigits.png`
- `01-01.png`
- `Tiles(40x40)-01-01.png` (because what counts is that last two groups)

Of course, the determination of which group of digits is the row and which is the column is under the control of the `Rows/Columns order` parameter.