gcode2image 2.4.5__py3-none-any.whl → 2.4.6__py3-none-any.whl

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: gcode2image
3
- Version: 2.4.5
3
+ Version: 2.4.6
4
4
  Summary: gcode2image: convert gcode to image.
5
5
  Keywords: engraving,laser,image,laser engraving,PWM,gcode
6
6
  Author-email: Johannes Noordanus <mailjohannes.mailnoordanus@gmail.com>
@@ -0,0 +1,6 @@
1
+ gcode2image.py,sha256=1onp8JYewcL5Y4XaqNFE2PfVO1CVSZSqK2BWQXRjFY4,18090
2
+ gcode2image-2.4.6.dist-info/entry_points.txt,sha256=3WTwx9hWoGPO7A4sCDOWktfO-uanp6gKGl25rZ3UHjo,48
3
+ gcode2image-2.4.6.dist-info/licenses/LICENSE,sha256=ghSxQl_EUJUTiu712NkZkroJHvgOrR0j4CddAq8Y7Tc,1085
4
+ gcode2image-2.4.6.dist-info/WHEEL,sha256=lqN8jXt_QloFOGcx9kStvWbryhfEXoI2F2z-YURm350,81
5
+ gcode2image-2.4.6.dist-info/METADATA,sha256=EEXel4rA4qUIFFYArbTZxFRGSCAd5SihD5U579blFPM,4585
6
+ gcode2image-2.4.6.dist-info/RECORD,,
gcode2image.py CHANGED
@@ -2,14 +2,27 @@
2
2
  """
3
3
  gcode2image: convert gcode to image.
4
4
  """
5
- __version__ = "2.4.5"
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: gcode file not well formed: missing move commands (X<nr> and or Y<nr> coordinates), exit ...")
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}>",
@@ -1,6 +0,0 @@
1
- gcode2image.py,sha256=mLzH8VjwCO4I5gpcZdi03koCTqe5MAzVIm4waJtftf4,17638
2
- gcode2image-2.4.5.dist-info/entry_points.txt,sha256=3WTwx9hWoGPO7A4sCDOWktfO-uanp6gKGl25rZ3UHjo,48
3
- gcode2image-2.4.5.dist-info/licenses/LICENSE,sha256=ghSxQl_EUJUTiu712NkZkroJHvgOrR0j4CddAq8Y7Tc,1085
4
- gcode2image-2.4.5.dist-info/WHEEL,sha256=lqN8jXt_QloFOGcx9kStvWbryhfEXoI2F2z-YURm350,81
5
- gcode2image-2.4.5.dist-info/METADATA,sha256=VrNhqvGZEl4TNWeIf2hzOLXMFh9doYgZB8vYKKejT1I,4585
6
- gcode2image-2.4.5.dist-info/RECORD,,