gcode2image 2.4.4__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.4
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.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
 
@@ -25,7 +38,7 @@ def gcode2image(args) -> np.array:
25
38
  # set args
26
39
  gcode = args.gcode
27
40
 
28
- float_pattern = "[+\-]?[0-9]+(\.[0-9]+)?"
41
+ float_pattern = r"[+\-]?[0-9]+(\.[0-9]+)?"
29
42
 
30
43
  X_pattern = f"X{float_pattern}"
31
44
  Y_pattern = f"Y{float_pattern}"
@@ -248,7 +261,7 @@ def gcode2image(args) -> np.array:
248
261
 
249
262
  def get_gcode_info():
250
263
  nonlocal gcode
251
- gc_info = { 'min_X': None, 'min_Y': None, 'max_X': None, 'max_Y': None, 'max_S': None, 'pixelsize': None, 'M': None, 'max_laser_power': None }
264
+ gc_info = { 'min_X': None, 'min_Y': None, 'max_X': None, 'max_Y': None, 'max_S': None, 'pixelsize': None, 'M': None, 'max_image_laser_power': None }
252
265
 
253
266
  while True:
254
267
  line = gcode.readline()
@@ -289,7 +302,7 @@ def gcode2image(args) -> np.array:
289
302
  max_laser_power = re.search(f"^;.*maximum_image_laser_power:? +{float_pattern}", line)
290
303
  if max_laser_power:
291
304
  max_laser_power = re.search(f"maximum_image_laser_power:? +{float_pattern}", max_laser_power.group()).group()
292
- gc_info['max_laser_power'] = float(re.search(f"{float_pattern}", max_laser_power).group())
305
+ gc_info['max_image_laser_power'] = float(re.search(f"{float_pattern}", max_laser_power).group())
293
306
 
294
307
  return gc_info
295
308
 
@@ -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
@@ -319,18 +332,15 @@ def gcode2image(args) -> np.array:
319
332
 
320
333
  # handle pixel intensity
321
334
  if args.maxintensity is not None:
335
+ # commandline setting is followed
322
336
  max_laser_power = args.maxintensity
323
- elif gc_info['max_laser_power']:
324
- max_laser_power = gc_info['max_laser_power']
325
- print(f"maxintensity is set to {max_laser_power} (found within '{args.gcode.name}')")
326
337
  else:
327
- max_S = gc_info['max_S']
328
- if max_S and max_S > DEFAULT_MAX_LASER_POWER:
329
- # self calibrate
330
- max_laser_power = max_S
331
- else:
332
- max_laser_power = DEFAULT_MAX_LASER_POWER
333
- print(f"maxintensity is set to {max_laser_power} (option '--maxintensity' is not supplied or found in '{args.gcode.name}')")
338
+ max_laser_power = DEFAULT_MAX_LASER_POWER
339
+ if gc_info['max_image_laser_power']:
340
+ max_laser_power = gc_info['max_image_laser_power']
341
+ if gc_info['max_S'] and gc_info['max_S'] > max_laser_power:
342
+ max_laser_power = gc_info['max_S']
343
+ print(f"maxintensity is set to {max_laser_power}")
334
344
 
335
345
  # handle missing G1 and M3(4) commands
336
346
  M = gc_info['M']
@@ -448,8 +458,8 @@ def main() -> int:
448
458
 
449
459
  # Define command line argument interface
450
460
  parser = argparse.ArgumentParser(description='Convert a gcode file to image.')
451
- parser.add_argument('gcode', type=argparse.FileType('r'), default = sys.stdin, help='name of gcode file to convert')
452
- 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')
453
463
  parser.add_argument('--resolution', default=pixelsize_default, metavar=f"<default: {DEFAULT_RESOLUTION}>",
454
464
  type=float, help="define image resolution by pixel size (mm^2)")
455
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=jp9HD_Fl6oKRyJpVNltCeHnz-v4Z8dniWg4tvg57gPo,17792
2
- gcode2image-2.4.4.dist-info/entry_points.txt,sha256=3WTwx9hWoGPO7A4sCDOWktfO-uanp6gKGl25rZ3UHjo,48
3
- gcode2image-2.4.4.dist-info/licenses/LICENSE,sha256=ghSxQl_EUJUTiu712NkZkroJHvgOrR0j4CddAq8Y7Tc,1085
4
- gcode2image-2.4.4.dist-info/WHEEL,sha256=lqN8jXt_QloFOGcx9kStvWbryhfEXoI2F2z-YURm350,81
5
- gcode2image-2.4.4.dist-info/METADATA,sha256=JoCv8BDlaXgfjc6reGHapP5JHi2flMyW-ZJaNUiZh1o,4585
6
- gcode2image-2.4.4.dist-info/RECORD,,