gcode2image 2.4.5__tar.gz → 2.4.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,14 +2,27 @@
|
|
|
2
2
|
"""
|
|
3
3
|
gcode2image: convert gcode to image.
|
|
4
4
|
"""
|
|
5
|
-
__version__ = "2.4.
|
|
5
|
+
__version__ = "2.4.6"
|
|
6
6
|
|
|
7
7
|
import sys
|
|
8
8
|
import re
|
|
9
9
|
import argparse
|
|
10
10
|
from PIL import Image
|
|
11
|
+
from pathlib import Path
|
|
11
12
|
import numpy as np
|
|
12
13
|
|
|
14
|
+
def ext_check(expected_extension, openner):
|
|
15
|
+
def extension(filename):
|
|
16
|
+
suffixes = expected_extension.split(',')
|
|
17
|
+
|
|
18
|
+
for suffix in suffixes:
|
|
19
|
+
if filename.lower().endswith(suffix):
|
|
20
|
+
return openner(filename)
|
|
21
|
+
|
|
22
|
+
print(f"Error: unknown file extension '{Path(filename).suffix}', file extension should be one of {suffixes}, exit ...")
|
|
23
|
+
sys.exit(1)
|
|
24
|
+
return extension
|
|
25
|
+
|
|
13
26
|
# set to 10 pixels per mm
|
|
14
27
|
DEFAULT_RESOLUTION = .1
|
|
15
28
|
|
|
@@ -301,7 +314,7 @@ def gcode2image(args) -> np.array:
|
|
|
301
314
|
gc_info = get_gcode_info()
|
|
302
315
|
|
|
303
316
|
if gc_info['min_X'] is None or gc_info['min_Y'] is None or gc_info['max_X'] is None or gc_info['max_Y'] is None:
|
|
304
|
-
print(f"Error:
|
|
317
|
+
print(f"Error: cannot detect gcode, wrong file type?, exit ...")
|
|
305
318
|
sys.exit(1)
|
|
306
319
|
|
|
307
320
|
# handle resolution
|
|
@@ -445,8 +458,8 @@ def main() -> int:
|
|
|
445
458
|
|
|
446
459
|
# Define command line argument interface
|
|
447
460
|
parser = argparse.ArgumentParser(description='Convert a gcode file to image.')
|
|
448
|
-
parser.add_argument('gcode', type=argparse.FileType('r'), default = sys.stdin, help='name of gcode file to convert')
|
|
449
|
-
parser.add_argument('image', type=argparse.FileType('w'), help='image out')
|
|
461
|
+
parser.add_argument('gcode', type=ext_check('.gc,.gcode', argparse.FileType('r')), default = sys.stdin, help='name of gcode file to convert')
|
|
462
|
+
parser.add_argument('image', type=ext_check('.png,.jpg,.jpeg', argparse.FileType('w')), help='image out')
|
|
450
463
|
parser.add_argument('--resolution', default=pixelsize_default, metavar=f"<default: {DEFAULT_RESOLUTION}>",
|
|
451
464
|
type=float, help="define image resolution by pixel size (mm^2)")
|
|
452
465
|
parser.add_argument('--maxintensity', default=max_laser_power_default, metavar=f"<default: {DEFAULT_MAX_LASER_POWER}>",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|