diff --git a/draw.py b/draw.py index 7439e7d..fe262a8 100644 --- a/draw.py +++ b/draw.py @@ -4,6 +4,7 @@ Brings together the different components needed to make the drawing machine chooch. """ import os +import time import stream import linedraw @@ -14,11 +15,15 @@ def draw(rec_filename): it and streams the resulting G-code to the GRBL controller. """ print("Vectorizing " + rec_filename + "...") + then = time.time() linedraw.sketch(rec_filename) + print("Done! Took", "%.3f" % (time.time() - then), "seconds") gcode_filename = rec_filename.replace("received", "converted") gcode_filename = os.path.splitext(gcode_filename)[0] + ".ngc" print("Streaming " + gcode_filename + "...") + then = time.time() stream.stream(gcode_filename) + print("Done! Took", "%.3f" % (time.time() - then), "seconds") if __name__ == "__main__": diff --git a/linedraw.py b/linedraw.py index 93604eb..a404275 100644 --- a/linedraw.py +++ b/linedraw.py @@ -264,6 +264,9 @@ def hatch(image, sc=16): def sketch(path, export_path=None, resolution=1024, hatch_size=16, contour_simplify=2): image = Image.open(path) + if image._getexif().get(274): # "Orientation" + if image._getexif().get(274) > 4: # modes 5-8 indicate the image was rotated + image = image.rotate(-90, expand=True) image = image.convert("L") image = ImageOps.autocontrast(image ,10) @@ -271,12 +274,12 @@ def sketch(path, export_path=None, resolution=1024, hatch_size=16, contour_simpl lines = [] if draw_contours: width = int(resolution/contour_simplify) - height = int(resolution/contour_simplify*image.size[0]/image.size[1]) + height = int(resolution/contour_simplify*image.height/image.width) lines += getcontours(image.resize((width, height)), contour_simplify) if draw_hatch: width = int(resolution/hatch_size) - height = int(resolution/hatch_size*image.size[0]/image.size[1]) + height = int(resolution/hatch_size*image.height/image.width) lines += hatch(image.resize((width, height)), hatch_size) lines = sortlines(lines)