Skip to content

Commit

Permalink
Add README and update examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
Will McCutchen committed Jun 25, 2012
1 parent 715c3e6 commit f34addb
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 9 deletions.
58 changes: 58 additions & 0 deletions README.md
@@ -0,0 +1,58 @@
# Triangulizor

<img src="https://github.com/mccutchen/triangulizor/raw/master/examples/in.jpg" align="middle">
➡☁➡
<img src="https://github.com/mccutchen/triangulizor/raw/master/examples/out.png" align="middle">

## Usage

Triangulizor requires Python 2.7+ and the [Python Imaging Library][3]. First,
install `PIL` (usually this is as easy as `pip install pil`). Next, find an
image to triangulize! To generate the example above, either of these commands
will do the trick:

```bash
./triangulizor.py --debug --tile-size=16 examples/in.jpg
```

The `--debug` flag will cause the resulting image to be displayed immediately
instead of written to `stdout` or to disk. You can also pass in the URL to an
image that you want to process:

```bash
./triangulizor.py --debug --tile-size=16 https://github.com/mccutchen/triangulizor/raw/master/examples/in.jpg
```

All command line options are given below:

```bash
$ ./triangulizor.py --help
```

```
usage: triangulizor.py [-h] [-t TILE_SIZE] [-v] [-vv] [-d] [infile] [outfile]
Applies a "triangular pixel" effect to an image.
positional arguments:
infile Image to process (path or URL; defaults to STDIN)
outfile Output file (defaults to STDOUT)
optional arguments:
-h, --help show this help message and exit
-t TILE_SIZE, --tile-size TILE_SIZE
Tile size (must be divisible by 2; defaults to 20)
-v, --verbose Verbose output
-vv Very verbose output
-d, --debug Immediately display image instead of writing to
OUTFILE.
```

## Credits

This was inspired entirely by [this awesomely helpful blog post][1] by
[@revdancatt][2].

[1]: http://revdancatt.com/2012/03/31/the-pxl-effect-with-javascript-and-canvas-and-maths/
[2]: http://twitter.com/revdancatt
[3]: http://pypi.python.org/pypi/PIL
Binary file removed examples/a.jpg
Binary file not shown.
Binary file removed examples/b.jpg
Binary file not shown.
Binary file added examples/in.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/out.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 2 additions & 9 deletions triangulizor.py
@@ -1,13 +1,5 @@
#!/usr/bin/env python2.7

"""
triangulizor.py
Applies a "triangular pixel" effect to images. Inspired by:
* http://revdancatt.com/2012/03/31/the-pxl-effect-with-javascript-and-canvas-and-maths/
* https://github.com/revdancatt/GuardianAmbientHeadlineRadio
"""

import argparse
from cStringIO import StringIO
import logging
Expand Down Expand Up @@ -210,7 +202,8 @@ def even_int(x):
help='Image to process (path or URL; defaults to STDIN)')
arg_parser.add_argument(
'outfile', nargs='?', default=sys.stdout,
type=argparse.FileType('wb'))
type=argparse.FileType('wb'),
help='Output file (defaults to STDOUT)')
arg_parser.add_argument(
'-t', '--tile-size', type=even_int, default=20,
help='Tile size (must be divisible by 2; defaults to 20)')
Expand Down

0 comments on commit f34addb

Please sign in to comment.