cross-stitch

Interactively turn images into patterns for cross stitching
git clone git://src.adamsgaard.dk/cross-stitch
Log | Files | Refs

commit c2d40de0c1dea41320e984bbbc1a65c3d610baee
parent b27bd4e8db7fd4107c7a7825c6bc949cda7bbb67
Author: Anders Damsgaard <anders.damsgaard@geo.au.dk>
Date:   Thu, 13 Feb 2014 21:17:43 +0100

Use PIL

Diffstat:
MREADME.rst | 2+-
Mcross-stitch.py | 40+++++++++++++++++++++++++++-------------
2 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/README.rst b/README.rst @@ -7,7 +7,7 @@ https://github.com/anders-dc/cross-stitch Requirements ------------ -Python, Numpy, Matplotlib +Python 2 or 3, Python Imaging Library License ------- diff --git a/cross-stitch.py b/cross-stitch.py @@ -1,15 +1,13 @@ #!/usr/bin/env python -#import os, sys, getopt, Image +import sys import argparse +import Image +import numpy as np +import matplotlib.pyplot as plt -#import numpy as np -#import matplotlib.pyplot as plt - -class image: - def __init__(self, in_file_path): - pass +## Process input arguments ##################################################### program_description = \ '''Downsamples and modifies an image in order to create a pattern for cross stitching.''' @@ -18,12 +16,28 @@ parser.add_argument('--infile', '-i', metavar='FILENAME', type=str, nargs=1, required=True, help='input image to process') parser.add_argument('--outfile', '-o', metavar='FILENAME', type=str, nargs=1, required=True, help='save processed image as FILENAME') -parser.add_argument('--dpi', '-r', type=int, nargs=1, default=5, - help='output file resolution (dots per inch), default value = 5') +parser.add_argument('--width', '-w', type=int, nargs=1, default=20, + help='canvas width, default value = 20') args = parser.parse_args() infile = args.infile[0] outfile = args.outfile[0] -resolution = args.dpi -print infile -print outfile -print resolution +width = args.width + +## Read image ################################################################## +try: + im = Image.open(infile) +except IOError: + sys.stderr.write('could not open input file "' + infile + '"\n') + sys.exit(1) + +## Downsampling ################################################################ +hw_ratio = float(im.size[1])/im.size[0] +new_size = (width, int(round(hw_ratio*width))) +im = im.resize(new_size) + +## Process image colors ######################################################## + + +## Generate output plot ######################################################## + +