syoung / Image-Tiler (public) (License: GPLv3) (since 2020-02-29) (hash sha1)
Use a set of SVG or raster graphics tile images to generate a larger image.
No history found.

README.md:

Image Tiler

Program to generate a larger image made up of different image tiles of the same size. You can specify how the image tiles connect to each other using a configuration file. Written in Python 3.

Basic Usage

  1. Create a directory with multiple same-sized tile raster images:

    tiles
     ├─left-to-right.png
     ├─top-to-bottom.png
     └─left-top-right-and-bottom.png
  2. Create a proper configuration file (config.json) in JSON format:

    {
      "tiles": [
        {
          "filePath": "left-to-right.png",
          "weight": 5,
          "connectors": ["c", "", "c", ""]
        },
        {
          "filePath": "top-to-bottom.png",
          "weight": 5,
          "connectors": ["", "c", "", "c"]
        },
        {
          "filePath": "left-top-right-and-bottom.png",
          "weight": 1,
          "connectors": ["c", "c", "c", "c"]
        }
      ]
    }

    Each object in the list of tiles must have the following name-value pairs:

    <table> <thead> <tr> <th>Name</th> <th>Type</th> <th>Value</th> </tr> </thead> <tbody> <tr> <td>filePath</td> <td>String</td> <td>The (relative) path to the image file of the tile, e. g. <code>left-to-right.png</code></td> </tr> <tr> <td>weight</td> <td>Number</td> <td> This number controls the probability of the tile appearing in the generated image, the higher the more often. </td> </tr> <tr> <td>connectors</td> <td>Array of Strings</td> <td> Each tile has four connectors, specified in the order <em>left</em>, <em>top</em>, <em>right</em>, <em>bottom</em>. </td> </tr> </tbody> </table>

    To be placed in the grid, the connectors of the tile must match the adjacent tiles’ connectors.

    Example:

    {
      &quot;tiles&quot;: [
        {
          &quot;filePath&quot;: &quot;left-to-top.png&quot;,
          &quot;weight&quot;: 1,
          &quot;connectors&quot;: [&quot;horizontal&quot;, &quot;v&quot;, &quot;none&quot;, &quot;none&quot;]
        },
        {
          &quot;filePath&quot;: &quot;right-to-bottom.png&quot;,
          &quot;weight&quot;: 1.4,
          &quot;connectors&quot;: [&quot;none&quot;, &quot;none&quot;, &quot;horizontal&quot;, &quot;v&quot;]
        }
      ]
    }

    The tile left-to-top.png may be placed beneath the tile right-to-bottom.png because its top connector v matches the bottom connector v of right-to-bottom.png. Following this logic, the tile left-to-top.png may not be placed beneath another left-to-top.png tile because its top connector v does not match its bottom connector none.

  3. Call tiler.py passing the directory of tiles, the configuration file, and the desired number of tile rows (4) and columns (5) as arguments:

    tiler.py -d tiles -c config.json 4 5

    The resulting image is saved to output/tiled.

Working Example

https://rocketgit.com/user/syoung/Tile-Collections contains a set of tiles and a corresponding config.json.

$ git clone https://rocketgit.com/user/syoung/Tile-Collections
$ cd Tile-Collections/
$ tiler.py -c streets/config.json -d streets/png/ 5 6
INFO:No tile type provided; trying to guess tile type
INFO:Guessed tile type “r”
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/syoung/Image-Tiler

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/syoung/Image-Tiler

Clone this repository using git:
git clone git://git.rocketgit.com/user/syoung/Image-Tiler

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main