| @@ -1,3 +1,4 @@ | |||
| # coding: utf-8 | |||
| """ Converts pixel-art images into cross-stitch patterns. | |||
| This tool assumes that 1px = 1 stitch. | |||
| @@ -10,21 +11,24 @@ | |||
| * Add grid lines and edge labels to image. (DONE) | |||
| * Add legend to image, based on the `symbols` dictionary. (DONE) | |||
| * Correspond hex colors to floss colors, where possible. | |||
| * (Maybe) add stitch count for each color. (DONE) | |||
| * (Maybe) add GUI. | |||
| * (Maybe) add stitch count for each color. (DONE) | |||
| * (Maybe) add GUI. (DONE) | |||
| * Make sure legend width doesn't exceed image width. | |||
| """ | |||
| __author__ = "Noëlle Anthony" | |||
| __version__ = "0.3.2" | |||
| __version__ = "0.4.0" | |||
| import sys | |||
| from PIL import Image, ImageDraw | |||
| from collections import defaultdict | |||
| from gooey import Gooey, GooeyParser | |||
| def main(img_name): | |||
| def create_stitch(img_name, img_out, display): | |||
| img = Image.open(img_name) | |||
| oimg_name_bits = img_name.split(".") | |||
| oimg_name = "".join(oimg_name_bits[:-1]) + "_pattern." + oimg_name_bits[-1] | |||
| #oimg_name_bits = img_name.split(".") | |||
| #oimg_name = "".join(oimg_name_bits[:-1]) + "_pattern." + oimg_name_bits[-1] | |||
| oimg_name = img_out | |||
| w,h = img.size | |||
| @@ -115,13 +119,17 @@ def main(img_name): | |||
| draw.text((20, (h*10)+20), legend_out, fill=0) | |||
| oimg.save(oimg_name) | |||
| print("Saved {}".format(oimg_name)) | |||
| if display: | |||
| oimg.show() | |||
| @Gooey | |||
| def main(): | |||
| parser = GooeyParser() | |||
| parser.add_argument("img_name", help="The image file you want to convert", widget="FileChooser") | |||
| parser.add_argument("img_out", help="The name of the output pattern", widget="FileSaver") | |||
| parser.add_argument("--display", help="Display the image after creation", action="store_true") | |||
| args = parser.parse_args() | |||
| create_stitch(args.img_name, args.img_out, args.display) | |||
| if __name__ == "__main__": | |||
| #print(len(sys.argv)) | |||
| #print(sys.argv[1]) | |||
| if len(sys.argv) >= 2: | |||
| img_name = sys.argv[1] | |||
| else: | |||
| img_name = "test.png" | |||
| main(img_name) | |||
| main() | |||