# pixelsort: sorting image pixels into glitch streaks

> pixelsort is a small Python package that takes an image, decides which runs of pixels count as sortable, and rearranges each run by lightness, hue, saturation or intensity, producing the streaked look associated with glitch art. It suits a creative coder who wants the effect reproducible from a command line.

**satyarth/pixelsort** — Pixel sorting images in python.

- Repository: https://github.com/satyarth/pixelsort
- Stars: 876 · Forks: 89
- Language: Python
- License: MIT
- Published: 2026-10-20 · Updated: 2026-10-20 · Language: en
- Canonical page: https://hysenlabs.com/projects/satyarth-pixelsort

## What the effect actually is

The library does one specific thing, and the readme points at a written explanation and a community thread for the background rather than explaining it at length. The effect is the streaked, smeared look you see in glitch art, where a photograph has been cut into strips and each strip has been reordered so the colours run smoothly along its length. The mechanism is that the image is divided into intervals, and the pixels inside each interval are sorted by some property. The interesting part is that the intervals are not simply rows. The interval function decides which stretches of the image are worth sorting, and the sorting function decides the order within them, and those two choices are independent. That separation is what makes the tool more than a filter, because a picture with a bright sky and a dark foreground produces completely different results depending on where the boundaries fall. The readme also credits the original Processing script by Kim Asendorf as the starting point, and gives a tip on how to reproduce that original look, which is a useful anchor for anyone who wants the classic result rather than a new one.

## Command line and library use are both first class

There are two ways in, and the readme gives both. The command line install is the usual pip install followed by running the module:

```bash
pip install pixelsort
python3 -m pixelsort %PathToImage% [options]
```

As a library, the entry point takes and returns a Pillow image object, which is what makes it composable in a script:

```python
>>> from pixelsort import pixelsort
>>> from PIL import Image
>>> a = Image.open("examples/image.jpg")
>>> a
<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=576x324 at 0x7F8F6A2AC208>
>>> pixelsort(a)
<PIL.Image.Image image mode=RGBA size=576x324 at 0x7F8F66AA57B8>
```

The two representations in that transcript are worth noting, because they show the transformation the library performs. The input is a JPEG file in RGB mode and the output is an image in RGBA mode, so the sort adds an alpha channel. That is a small detail with practical consequences, since a script that saves the result as a JPEG will lose the transparency, and one that expects an RGB buffer will get four channels. The package itself is tiny, with the single runtime dependency being Pillow, and the setup file reads the requirements from a requirements file at the root, which keeps the dependency list in one place rather than in the setup configuration.

## Six interval functions, and they change everything

The interval function is the parameter that decides which parts of the image are rearranged, and there are six of them, and the default is threshold. The random function generates intervals at random with a linear distribution of widths by default, and the widths can be scaled with the characteristic length parameter. The edges function performs an edge detection to define the intervals, with the threshold setting used to tune it. The threshold function is the default, and it sorts only the pixels whose lightness falls between the lower and upper thresholds, which is why it produces the streak effect rather than mangling the whole frame. The waves function gives intervals of nearly uniform width, like a waveform, again controlled by the characteristic length. The file function takes intervals from another image that must be black and white and the same size as the input, and the file-edges variant does edge detection on that file instead. The none function sorts whole rows and only stops at the image borders, which is the most extreme option and the closest to a naive sort of every scanline.

## Five ways to order the pixels, and a set of tuning flags

The sorting function is the second half of the pair. Lightness is the default and sorts by the lightness of a pixel according to an HSL representation. Hue and saturation work the same way, also on an HSL basis, and intensity is the sum of all the RGB values, while minimum sorts on the smallest of the three RGB channels. The remaining flags are the tuning surface. The lower threshold asks how dark a pixel must be to count as a border, taking values from 0 to 1 with 0.25 as the default, and the upper threshold asks how bright a pixel must be for the same purpose with 0.8 as the default. The angle sets the direction of the sort in degrees, with 0 meaning horizontal. The randomness parameter is the one to understand carefully, because it is the percentage of intervals deliberately left unsorted, which is the difference between a clean streak and a broken one, and it is 0 by default. There is also an output path, which uses the current time for the file name when you do not give one, a mask image, a file of intervals, the logging level with WARNING as the default, and the characteristic length used by the random and waves modes.

## Reproducing the original look, and the two file based modes

The readme spends a paragraph on how to match Kim Asendorf's original Processing script, and the recipe is two passes rather than one. You sort vertically and then horizontally, in threshold mode, and the commands are given with an explicit angle:

```bash
python3 -m pixelsort %PathToImage% -a 90
python3 -m pixelsort %PathToSortedImage%
```

The angle of 90 makes the first pass vertical, and the second pass takes the already sorted image and sorts it the other way, which is the detail that makes the result look like the original rather than like a single-direction smear. The two file based modes are how you control the shape rather than the appearance. To take the intervals from an image, the file must be black and white and the same size as the input:

```bash
python3 -m pixelsort examples/image.jpg -i file -f examples/intervals.png 
```

And the mask does the same job for choosing which parts of the image to leave alone, with the same black and white and same size requirement, combined with a random interval mode:

```bash
python3 -m pixelsort examples/image.jpg -i random -c 20 -m examples/mask.png
```

The mask is the more interesting of the two, because it lets you say where the effect should not appear, which is what separates a deliberate treatment from a filter applied to everything.

## What the project is, and what is still on the list

The package is minimal in the way a focused tool usually is. The repository contains the package directory, a requirements file with the single dependency, a setup file, a manifest for the package data, a licence, and an examples directory that holds the sample images used in the readme, including the intervals and mask images for the file and mask modes. The setup metadata lists the author, the description as an image pixelsorter for Python, the project URL, and classifiers for Python, the MIT licence and an operating system independent environment. The one item on the todo list is allowing different intervals for different channels, which is a real limitation given that the sorting functions all operate on an HSL or RGB basis per pixel. It is worth noting what is not on the list, because it tells you the scope. There is no mention of a graphical interface, no mention of a plugin system for other image libraries, and no mention of batch processing, which for a tool that takes one file at a time on the command line means a shell loop is the way to process a folder. The project is MIT licensed, the last push was on 2026-09-03, and the current release is v1.0.2 from the same day.

## Conclusion

pixelsort is a good fit for a creative coder or a designer who wants the pixel sorting effect with the parameters exposed rather than a fixed script, since the interval and sorting functions are separate choices and the library can be called from a script as easily as from the command line. It is the wrong tool if you want a general image processing library, since it does one thing, and it is the wrong tool if you need speed on large images, because the implementation is straightforward Python over pixels and the readme does not make performance claims. It is also the wrong tool if you expect a graphical editor, since there is none. Before adopting it, note the Python version situation, since the documentation says it should work in both Python 2 and 3 with 3 recommended, and check the file based interval modes, which require a black and white image of the same size as the input. The project is MIT licensed, the last push was on 2026-09-03, and the current release is v1.0.2 from the same day.

## FAQ

### How do I run pixelsort from the command line?

Install it with pip install pixelsort and run the module with the path to the image and any options, for example python3 -m pixelsort with the path and flags. The output path defaults to a file name built from the current time, and the logging level defaults to WARNING with DEBUG, INFO, WARNING, ERROR and CRITICAL available.

### What are the interval functions in pixelsort?

Six. Random generates intervals at random with a linear distribution of widths, edges performs an edge detection to define them, threshold sorts only the pixels whose lightness falls between the two thresholds and is the default, waves gives intervals of nearly uniform width, file takes the intervals from a black and white image of the same size, file-edges does edge detection on that file, and none sorts whole rows and stops only at the image borders.

### Which sorting functions does pixelsort support?

Five. Lightness is the default and sorts by the lightness of the pixel in an HSL representation, hue and saturation work the same way on an HSL basis, intensity uses the sum of the RGB values, and minimum sorts on the smallest of the three channels. The sorting function is chosen with the -s flag and the interval function with the -i flag.

### How do I reproduce the original Asendorf pixel sorting look?

Sort vertically and then horizontally in threshold mode, by running the tool with an angle of 90 and then running it again on the sorted output. The readme gives both commands explicitly, and notes that the project is based on an earlier gist and credits Kim Asendorf's original Processing script.

### Can I use pixelsort as a Python library?

Yes. The package exports a pixelsort function that takes a Pillow image and returns a sorted one, so you can open an image with the Pillow Image class and pass it straight in. The readme notes that the output is in RGBA mode while a JPEG input is RGB, since the sort adds an alpha channel. The only runtime dependency is Pillow.

## Sources

- [Issues](https://github.com/satyarth/pixelsort/issues)
- [License: MIT](https://github.com/satyarth/pixelsort/blob/master/LICENSE)
- [README](https://github.com/satyarth/pixelsort/blob/master/README.md)
- [Releases](https://github.com/satyarth/pixelsort/releases)
- [satyarth/pixelsort on GitHub](https://github.com/satyarth/pixelsort)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/satyarth-pixelsort
