/img2texture

Programmable Module and CLI for converting images to seamless tiles

Primary LanguagePythonMIT LicenseMIT

PyPI version shields.io Generic badge Generic badge Downloads

img2texture - original

This is a fork of the original img2texture for programmable usage as well as CLI usage.

The resulting tiles can be used as textures in games, compositing and 3D modeling applications, etc.

⚠️ If the images below are not displayed, check out the original of this document on GitHub.

Original image x4

Source tiled

Orion galaxy by NASA/ESA, in four copies side by side.

We cannot use the original image as an endless space background: the seams are visible.

Converted image x4

Converted tiled

The result of img2texture, in four copies side by side.

The image is slightly reduced in size and the edges are modified with alpha-blending.

The converted image can be tiled and panned in any direction. It will feel endless and seamless.

Install

pip install git+https://github.com/WASasquatch/img2texture.git

Direct Usage

Direct usage with Ptyhon

from PIL import Image
from img2texture import img2tex
from img2texture._tiling import tile

image = Image.open('/content/input_.png')

texture = img2tex(source=image, target=None, pct=0.5)
tiled_texture = tile(src=texture, dst=None, horizontal=2, vertical=2)

texture.show()
tiled_texture.show()

Run

Create new seamless.jpg from source.jpg.

img2texture /path/to/source.jpg /path/to/seamless.jpg 

--overlap

The --overlap option determines how much of the image will be used to hide the seams.

For example, the following command uses 25% of the width and 25% of the height of the original image:

img2texture source.jpg seamless.jpg --overlap 0.25 

Increasing the value makes the seam less visible. However, the image becomes smaller.

Sample images

⚠️ If the images below are not displayed, check out the original of this document on GitHub.

--overlap 0.05

5% of the width and 5% of the height are used to mask the seam.

--overlap 0.05

--overlap 0.4

40% of the width and 40% of the height are used to mask the seam.

--overlap 40

--tile

The --tile option will create a 2x2 tiled version in addition to the converted image.

The following command will create seamless.jpg and seamless_2x2.jpg.

img2texture source.jpg seamless.jpg --tile 

All the samples on this page were created with --tile.

License

Copyright © 2021 Artsiom iG. Released under the MIT License.