Checks whether an image tiles without a visible seam: it compares the wrap-around edges with ordinary neighbouring pixels. One file, seamcheck.py; needs Python 3 and Pillow.
python3 -m pip install Pillow
python3 seamcheck.py fixtures/bad.png --annotate annotated.png
The picture above is fixtures/bad.png placed 2x2 (left) and that annotated.png (right); rebuild it with python3 tools/make_readme_picture.py. Exit code 0 tiles, 1 does not tile, 2 cannot run.
The default check is a quick filter: it missed 5 of 12 synthetic seams, see What it does not tell you.
python3 seamcheck.py tile.png
How it works: repeat the image on a grid. Its left and right edges become neighbours, and so do its top and bottom edges. seamcheck compares how much those wrap-around neighbours differ with how much ordinary neighbouring pixels inside the image differ. It prints one line per direction and a verdict, for example:
left/right: seam mean 84.67 max 254, interior mean 0.67, limit 2.00 -> SEAM
top/bottom: seam mean 84.67 max 254, interior mean 0.67, limit 2.00 -> SEAM
DOES NOT TILE
Numbers are mean and maximum absolute channel differences (0 to 255) between the last and first column (or row), and the mean difference between ordinary neighbouring columns (rows).
Exit code: 0 tiles, 1 does not tile, 2 cannot run (unreadable or oversized file, more than 8 bits per channel, image smaller than 3x3, unwritable preview, bad option such as --ratio 0).
Options:
-
--ratio Rthe seam may differ at most R times more than interior neighbours (default 2.0). The seam passes if its mean difference is at or below max(R x interior mean, 2.0), so on very smooth images a seam of up to 2 (of 255) passes whatever R is. -
--exactinstead require the first and last column, and the first and last row, to be identical. This is the convention of images made by loomwork; other tiles can pass the default test and fail this one. -
--lenientcompare the seam with the mean of the interior differences that are not zero, instead of the mean of all of them. Use it when a regular stripe or fine repeating pattern is flagged although it tiles. It only ever removes failures; it never adds one, but it can miss real seams (a one-pixel shift). With--alpha,--lenientcan also pass an alpha seam when the interior has an equally large step, because its limit uses the largest interior step: study numbers in docs/reading-a-report.md. Not allowed together with--exact(exit 2); works with--ratio,--fix,--previewand, viaargs, in the folder tool and the GitHub Action. Without the flag nothing changes. -
--fix FILEalso write a tileable-ish version of the image to FILE (PNG, RGB, same size; transparency is dropped): the image is cross-faded with its own half-shifted copy, so its seam is as smooth as one step of the image itself. That is usually enough to pass the default check, but not always, so runseamcheckon the output; a wide band near the edges shows as ghosting and lost detail. A quick repair, not a good one; failure counts in docs/reading-a-report.md. The verdict printed and the exit code describe the input image. FILE must not be the input file or the--previewfile (exit 2). -
--quietprint only the verdict line (TILESorDOES NOT TILE) on standard output and nothing else. Exit codes are unchanged, and errors still go to standard error with exit 2. Works with--ratio,--exact,--lenient,--fix,--previewand--annotate, which write their files as usual and print nothing. -
--explainafter each result line, add one to three indented plain-language lines (one for an--exactpass): what the seam mean and the interior mean are, and a suggested next step (--preview,--fix,--lenient). The result lines, the verdict and the exit codes are unchanged; the extra lines never contain->. Cannot be combined with--quiet(exit 2). The advice is a rule of thumb, not a measurement. In the folder tool and the GitHub Action--explainvia--argsdoes nothing visible, because they keep only the lines containing->. -
--preview FILEwrite the image shifted by half its size, wrapping round, as a PNG. A seam shows up as a visible line through the middle. -
--alphaopt in: for an image that has an alpha channel (RGBA, LA, palette with transparency), also compare the alpha across the wrap-around edges with the same rule (so--ratio,--exactand--lenientapply) and print two more result lines,alpha left/rightandalpha top/bottom, in the same format with->. A seam in either makes the verdict DOES NOT TILE (exit 1). Without the flag the output and exit codes are byte-identical to before, for every input, and an image with alpha is still read as RGB. On an image with no alpha channel the flag changes nothing on standard output; a note goes to standard error. Limits: colour is still compared as RGB, so a transparent pixel is compared by its stored colour, which may be meaningless;--fixdoes not repair alpha (its output is RGB);--explainworks on the alpha lines,--quiethides them but the verdict and exit code still include them; in the folder tool and the Action pass it via--args, and the hook accepts--alpha. Checked only on small synthetic images, not on a collection of real textures. -
--explainon an image with alpha adds one more hint (only with--explain; default output and exit codes are unchanged): when an RGB edge line fails and at least half of the edge pixel pairs whose stored colour differs are fully transparent (alpha 0) on both sides, it says that colour stored under transparent pixels is being compared and suggests clearing it. There is no flag for this; see the Pillow recipe in docs/reading-a-report.md. The hint is a guess from the two edge lines only: it can be wrong, it does not fire when the transparent pixels are partly opaque (alpha 1 to 254), and it needs the edge pixels to be exactly alpha 0. It also fires under--exact. If the image still fails after clearing, the visible part of the edge is also seamed. Tested on a few synthetic sprites only. -
Note:
--explain,--alpha, the hint above and--set(below) are on main and not in the v0.3.0 release; the pinned@v0.3.0action and hook do not have them yet. -
--set MAP [MAP ...]check several maps of one texture (base colour, roughness, height, ...) in one call:seamcheck --set A.png B.png C.png. Each file gets exactly the ordinary single-image check; the output is one line per map (NAME: tiles|does not tile (left/right ok, top/bottom SEAM)), a note on whether all maps have the same size (a different size is only reported, it does not change the verdict), the linefirst map that breaks the tile: NAMEif any, thenSET TILESorSET DOES NOT TILE(exit 0 / 1; 2 if a file cannot be read). Takes--ratio,--exact,--lenientand--quietonly; other options are refused (exit 2). Without--set, output and exit codes are unchanged; only the usage/help text differs, because it now lists--set. Limits: it is a loop, not a new measurement; every map is compared as colour (RGB), so a normal map is not treated as vectors, which may flag or pass it wrongly; there is no check that the maps belong together. Checked only on small synthetic images, not on real texture sets. -
--annotate OUT.pngwrite the image tiled 2x2 as a PNG, with a red line over the two pixel lines either side of each join whose axis the check reports as a seam, and below and to the right a strip per axis whose bar lengths show the step between each line and the next (relative to the largest step on that axis; the seam's own bar is red). With--exactthe positions where the two wrap-around edge pixels differ are marked in blue. It shows where, not whether: the verdict printed and the exit code are unchanged, and without the flag nothing changes. OUT.png must not be the input file,--fixor--previewfile (exit 2). The folder tool and the GitHub Action take it differently, see below.
The repository is also a composite action that checks every PNG in a folder and fails the job if any has a seam:
- uses: actions/checkout@v4
- uses: donkamonka17-spec/seamcheck@v0.3.0
with:
path: textures # folder, searched recursively (default ".")
exclude: | # optional globs relative to path, one per line
ui/*
args: --ratio 1.5 # optional extra seamcheck options (not --fix or --preview)
It prints one line per file (OK, SEAM or ERROR) with the numbers, adds an error annotation naming each file with a seam, writes a table to the job summary, and checks all files before failing. The step fails if any file has a seam, and also if no PNG is found or a file cannot be read (an unreadable file is never counted as a pass). Optionally, python3 tools/check_folder.py --annotate-dir DIR FOLDER (action input annotate-dir, default empty) writes one annotated PNG per failing texture into DIR, as --annotate does for one file. DIR is created if absent, names come from the file's path plus a short hash so equal basenames in different folders do not collide, nothing existing is overwritten, and without it nothing changes. The annotate-dir input runs in this repository's CI on a Linux and a Windows runner (one failing file each); other Windows paths are untested. --quiet is refused in --args (exit 2) because it would empty the per-file numbers. --quiet and this refusal are on main, after the v0.3.0 tag, so a workflow pinned to v0.3.0 has neither. Without GitHub, python3 tools/check_folder.py FOLDER does the same and exits 0, 1 (a seam) or 2 (nothing has a seam but something could not be checked). The action installs the latest Pillow with pip. This repository's own CI runs the action on its fixtures: it must pass on a folder of good tiles and fail with a seam in it. Nobody outside has used it yet.
repos:
- repo: https://github.com/donkamonka17-spec/seamcheck
rev: v0.3.0 # a tag or commit that contains .pre-commit-hooks.yaml
hooks:
- id: seamcheck # optional: args: [--ratio, "1.5"] or [--exact]
The hook checks each staged PNG and fails the commit if any has a seam (exit 1) or cannot be read (exit 2). Use v0.2.0 or any later tag or commit of this repository.
How-to: Check whether a texture tiles seamlessly.
| Tool | 0 | 1 | 2 |
|---|---|---|---|
seamcheck.py FILE |
tiles: TILES |
seam: DOES NOT TILE |
cannot run: seamcheck: cannot read broken.png: cannot identify image file ... |
tools/check_folder.py FOLDER |
no seam, all checked: 1 checked, 0 with a seam, 0 could not be checked |
at least one seam: 2 checked, 1 with a seam, 0 could not be checked |
no seam but something could not be checked: 1 checked, 0 with a seam, 1 could not be checked |
| pre-commit hook | every file tiles | any file has a seam (DOES NOT TILE) |
no seam, but a file could not be read (seamcheck: cannot read ...) |
A seam takes priority over an unreadable file (1 before 2) in the folder tool and the hook.
In a small check of 36 textures that their publishers call seamless, the default test passed 35, missed a seam that both reviewers saw clearly in a busy texture, and failed one texture that looked fine: see docs/in-the-wild.md. Treat a pass as a quick filter and look at --preview. A one-page guide to reading the output (based on that small study, two reviewers) shows how.
This is a pixel comparison of two edges. It cannot see a repeating pattern that looks odd, or a seam that is as smooth as the image's own texture. The ratio rule is a judgement, not a measurement of how it looks to a person; try --preview on anything borderline. Images are read as RGB; transparency is ignored unless you pass --alpha, which compares only the alpha channel's edges (see Options). An 8000 by 8000 noise image took about 1.4 seconds and about 280 MB of memory at peak (worst of three runs; measured on one machine) (an earlier pixel-loop version took about 66 seconds and 0.5 GB). With --alpha, an 8000 by 8000 RGBA image took about 2.4 seconds and 840 MB at peak (worst of three runs, one machine), because the file is read a second time for the alpha channel. Printed numbers can differ from that earlier version in the last digit.
python3 -m unittest discover -s tests
The fixtures in fixtures/ (good.png tiles, bad.png does not) are made by tools/make_fixtures.py. CI runs the tests on Python 3.12 only, with Pillow 10.4.0, 11.3.0 and the latest release, and checks the exit codes from the command line.
MIT, see LICENSE.
