gcode2image 2.4.1__tar.gz → 2.4.3__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.
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: gcode2image
|
|
3
|
-
Version: 2.4.
|
|
3
|
+
Version: 2.4.3
|
|
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>
|
|
7
7
|
Requires-Python: >=3.7
|
|
8
8
|
Description-Content-Type: text/markdown
|
|
9
9
|
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
-
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: numpy >= 1.24.3, <= 2.4.6
|
|
11
12
|
Requires-Dist: Pillow >= 9.5.0
|
|
12
13
|
Project-URL: Home, https://github.com/johannesnoordanus/gcode2image
|
|
13
14
|
|
|
@@ -15,7 +16,7 @@ Project-URL: Home, https://github.com/johannesnoordanus/gcode2image
|
|
|
15
16
|
|
|
16
17
|
Commanline tool to convert gcode to pixel exact image files.
|
|
17
18
|
|
|
18
|
-
This 2D viewer - images are 2D (no Z coordinates) - has as strong points that it shows gray levels and thus is able to show a realistic representation of laser engravings. Images can be viewed while converting gcode and the exact placing and size of the gcode can be shown. Since version 2.4.0 repeated writes to the same pixel locations
|
|
19
|
+
This 2D viewer - images are 2D (no Z coordinates) - has as strong points that it shows gray levels and thus is able to show a realistic representation of laser engravings. Images can be viewed while converting gcode and the exact placing and size of the gcode can be shown. Since version 2.4.0 repeated writes to the same pixel locations can be shown (option --incremental). This means that the simulated engraving is pretty close to actual laser engraving.
|
|
19
20
|
It is also possible to show speed movement *G0* code.
|
|
20
21
|
|
|
21
22
|
A typical command:
|
|
@@ -39,10 +40,15 @@ Depends on python libraries numpy and PIL.
|
|
|
39
40
|
```
|
|
40
41
|
> pip install gcode2image
|
|
41
42
|
```
|
|
43
|
+
Note that some managed linux distributions do not allow system wide installs using *pip*, in that case use *pipx*:
|
|
44
|
+
```
|
|
45
|
+
> pipx install gcode2image
|
|
46
|
+
```
|
|
42
47
|
### Usage:
|
|
43
48
|
```
|
|
44
49
|
$ gcode2image --help
|
|
45
|
-
usage: gcode2image [-h] [--resolution <default: 0.1>] [--maxintensity <default: 255>] [--showimage] [--showG0] [--showorigin] [--flip] [--grid] [-V]
|
|
50
|
+
usage: gcode2image [-h] [--resolution <default: 0.1>] [--maxintensity <default: 255>] [--showimage] [--showG0] [--showorigin] [--flip] [--grid] [--incremental] [-V]
|
|
51
|
+
gcode image
|
|
46
52
|
|
|
47
53
|
Convert a gcode file to image.
|
|
48
54
|
|
|
@@ -61,6 +67,7 @@ options:
|
|
|
61
67
|
--showorigin show image origin (0,0)
|
|
62
68
|
--flip flip image updown
|
|
63
69
|
--grid show a grid 10mm wide
|
|
70
|
+
--incremental show incremental burns
|
|
64
71
|
-V, --version show version number and exit
|
|
65
72
|
```
|
|
66
73
|
### Example:
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Commanline tool to convert gcode to pixel exact image files.
|
|
4
4
|
|
|
5
|
-
This 2D viewer - images are 2D (no Z coordinates) - has as strong points that it shows gray levels and thus is able to show a realistic representation of laser engravings. Images can be viewed while converting gcode and the exact placing and size of the gcode can be shown. Since version 2.4.0 repeated writes to the same pixel locations
|
|
5
|
+
This 2D viewer - images are 2D (no Z coordinates) - has as strong points that it shows gray levels and thus is able to show a realistic representation of laser engravings. Images can be viewed while converting gcode and the exact placing and size of the gcode can be shown. Since version 2.4.0 repeated writes to the same pixel locations can be shown (option --incremental). This means that the simulated engraving is pretty close to actual laser engraving.
|
|
6
6
|
It is also possible to show speed movement *G0* code.
|
|
7
7
|
|
|
8
8
|
A typical command:
|
|
@@ -26,10 +26,15 @@ Depends on python libraries numpy and PIL.
|
|
|
26
26
|
```
|
|
27
27
|
> pip install gcode2image
|
|
28
28
|
```
|
|
29
|
+
Note that some managed linux distributions do not allow system wide installs using *pip*, in that case use *pipx*:
|
|
30
|
+
```
|
|
31
|
+
> pipx install gcode2image
|
|
32
|
+
```
|
|
29
33
|
### Usage:
|
|
30
34
|
```
|
|
31
35
|
$ gcode2image --help
|
|
32
|
-
usage: gcode2image [-h] [--resolution <default: 0.1>] [--maxintensity <default: 255>] [--showimage] [--showG0] [--showorigin] [--flip] [--grid] [-V]
|
|
36
|
+
usage: gcode2image [-h] [--resolution <default: 0.1>] [--maxintensity <default: 255>] [--showimage] [--showG0] [--showorigin] [--flip] [--grid] [--incremental] [-V]
|
|
37
|
+
gcode image
|
|
33
38
|
|
|
34
39
|
Convert a gcode file to image.
|
|
35
40
|
|
|
@@ -48,6 +53,7 @@ options:
|
|
|
48
53
|
--showorigin show image origin (0,0)
|
|
49
54
|
--flip flip image updown
|
|
50
55
|
--grid show a grid 10mm wide
|
|
56
|
+
--incremental show incremental burns
|
|
51
57
|
-V, --version show version number and exit
|
|
52
58
|
```
|
|
53
59
|
### Example:
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"""
|
|
3
3
|
gcode2image: convert gcode to image.
|
|
4
4
|
"""
|
|
5
|
-
__version__ = "2.4.
|
|
5
|
+
__version__ = "2.4.3"
|
|
6
6
|
|
|
7
7
|
import sys
|
|
8
8
|
import re
|
|
@@ -35,6 +35,11 @@ def gcode2image(args) -> np.array:
|
|
|
35
35
|
|
|
36
36
|
invert_intensity = True
|
|
37
37
|
|
|
38
|
+
cummulative = False
|
|
39
|
+
if 'incremental' in vars(args):
|
|
40
|
+
cummulative = args.incremental
|
|
41
|
+
|
|
42
|
+
|
|
38
43
|
def line_slope(p1: (int,int), p2: (int,int)):
|
|
39
44
|
"""Calculate the slope of the line p1p2"""
|
|
40
45
|
x1, y1 = p1[0], p1[1]
|
|
@@ -56,41 +61,43 @@ def gcode2image(args) -> np.array:
|
|
|
56
61
|
return round(y)
|
|
57
62
|
|
|
58
63
|
def draw(img, start: (int,int), end: (int,int), color):
|
|
64
|
+
"""
|
|
65
|
+
Draw a line from 'start' (x,y) to one point short of 'end' (x,y)
|
|
66
|
+
"""
|
|
59
67
|
slope = line_slope(start, end)
|
|
60
68
|
offset = line_offset(start, end)
|
|
61
69
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
img[y2,start[0]] = color
|
|
71
|
-
else:
|
|
72
|
-
# non vertical line
|
|
73
|
-
dix = 1 if end[0] > start[0] else -1
|
|
74
|
-
prev = start
|
|
75
|
-
for x in range(start[0], end[0] + dix, dix):
|
|
76
|
-
y = line(x,slope,offset)
|
|
77
|
-
if abs(y - prev[1]) > 1:
|
|
78
|
-
di = 1 if y > prev[1] else -1
|
|
79
|
-
for y1 in range(prev[1], y, di):
|
|
80
|
-
#print("y1:",(x,y1))
|
|
81
|
-
if img[y1,x] != 255:
|
|
82
|
-
img[y1,x] = max(img[y1,x] - color, 0)
|
|
83
|
-
else:
|
|
84
|
-
img[y1,x] = color
|
|
85
|
-
|
|
86
|
-
if x != end[0]:
|
|
87
|
-
if img[y,x] != 255:
|
|
88
|
-
img[y,x] = max(img[y,x] - color, 0)
|
|
70
|
+
if color != 255:
|
|
71
|
+
# write non white colors
|
|
72
|
+
if slope == 1 and ((start[0] - end[0]) != (start[1] - end[1])):
|
|
73
|
+
# vertical line (not a 45 degrees line)
|
|
74
|
+
diy = 1 if end[1] > start[1] else -1
|
|
75
|
+
for y2 in range(start[1], end[1] + diy, diy):
|
|
76
|
+
if cummulative and img[y2,start[0]] != 255:
|
|
77
|
+
img[y2,start[0]] = max(img[y2,start[0]] - color, 0)
|
|
89
78
|
else:
|
|
90
|
-
img[
|
|
91
|
-
|
|
79
|
+
img[y2,start[0]] = color
|
|
80
|
+
else:
|
|
81
|
+
# non vertical line
|
|
82
|
+
dix = 1 if end[0] > start[0] else -1
|
|
83
|
+
prev = start
|
|
84
|
+
for x in range(start[0], end[0] + dix, dix):
|
|
85
|
+
y = line(x,slope,offset)
|
|
86
|
+
if abs(y - prev[1]) > 1:
|
|
87
|
+
di = 1 if y > prev[1] else -1
|
|
88
|
+
for y1 in range(prev[1], y, di):
|
|
89
|
+
if cummulative and img[y1,x] != 255:
|
|
90
|
+
img[y1,x] = max(img[y1,x] - color, 0)
|
|
91
|
+
else:
|
|
92
|
+
img[y1,x] = color
|
|
93
|
+
|
|
94
|
+
if x != end[0]:
|
|
95
|
+
if cummulative and img[y,x] != 255:
|
|
96
|
+
img[y,x] = max(img[y,x] - color, 0)
|
|
97
|
+
else:
|
|
98
|
+
img[y,x] = color
|
|
92
99
|
|
|
93
|
-
|
|
100
|
+
prev = (x,y)
|
|
94
101
|
|
|
95
102
|
def pixel_range(ra, dY, dX, pixelsize, img_height, img_width):
|
|
96
103
|
"""
|
|
@@ -452,6 +459,7 @@ def main() -> int:
|
|
|
452
459
|
parser.add_argument('--showorigin', action='store_true', default=False, help='show image origin (0,0)' )
|
|
453
460
|
parser.add_argument('--flip', action='store_true', default=False, help='flip image updown' )
|
|
454
461
|
parser.add_argument('--grid', action='store_true', default=False, help='show a grid 10mm wide' )
|
|
462
|
+
parser.add_argument('--incremental', action='store_true', default=False, help='show incremental burns' )
|
|
455
463
|
parser.add_argument('-V', '--version', action='version', version='%(prog)s ' + __version__, help="show version number and exit")
|
|
456
464
|
args = parser.parse_args()
|
|
457
465
|
|
|
File without changes
|