image2gcode 2.2.1__tar.gz → 2.3.0__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,13 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: image2gcode
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.3.0
|
|
4
4
|
Summary: image2gcode: convert an image to gcode.
|
|
5
5
|
Keywords: engraving,laser,image,laser engraving,PWM,gcode
|
|
6
6
|
Author-email: Johannes Noordanus <mailjohannes.mailnoordanus@gmail.com>
|
|
7
|
-
Requires-Python: >=3.
|
|
7
|
+
Requires-Python: >=3.7
|
|
8
8
|
Description-Content-Type: text/markdown
|
|
9
9
|
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
-
Requires-Dist: gcode2image >= 2.
|
|
10
|
+
Requires-Dist: gcode2image >= 2.2
|
|
11
11
|
Requires-Dist: numpy >= 1.24.3
|
|
12
12
|
Requires-Dist: Pillow >= 9.5.0
|
|
13
13
|
Project-URL: Home, https://github.com/johannesnoordanus/image2gcode
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"""
|
|
3
3
|
image2gcode: convert an image to gcode.
|
|
4
4
|
"""
|
|
5
|
-
__version__ = "2.
|
|
5
|
+
__version__ = "2.3.0"
|
|
6
6
|
|
|
7
7
|
import sys
|
|
8
8
|
import math
|
|
@@ -18,24 +18,28 @@ try:
|
|
|
18
18
|
except ImportError:
|
|
19
19
|
GCODE2IMAGE = False
|
|
20
20
|
|
|
21
|
-
def loadImage(
|
|
21
|
+
def loadImage(args):
|
|
22
22
|
"""
|
|
23
|
-
loadimage: load an image and convert it to b&w
|
|
23
|
+
loadimage: load an image and convert it to b&w and white background
|
|
24
24
|
"""
|
|
25
25
|
|
|
26
|
-
if
|
|
26
|
+
if args.image:
|
|
27
27
|
# add alpha channel
|
|
28
|
-
img = Image.open(
|
|
28
|
+
img = Image.open(args.image.name).convert("RGBA")
|
|
29
29
|
|
|
30
30
|
# create a white background and add it to the image
|
|
31
31
|
img_background = Image.new(mode = "RGBA", size = img.size, color = (255,255,255))
|
|
32
32
|
img = Image.alpha_composite(img_background, img)
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
img = img.resize(img.size, Image.Resampling.LANCZOS).convert("L")
|
|
36
|
-
if showimage:
|
|
34
|
+
if args.showimage:
|
|
37
35
|
img.show()
|
|
38
36
|
|
|
37
|
+
# set image resolution based on a DPI of 254 (10 pixels per mm) and given pixelsize
|
|
38
|
+
size = (round(img.size[0]/(10 * args.pixelsize)) + 1, round(img.size[1]/(10 *args.pixelsize)) + 1)
|
|
39
|
+
|
|
40
|
+
# convert image to black&white and resize
|
|
41
|
+
img = img.resize(size, Image.Resampling.LANCZOS).convert("L")
|
|
42
|
+
|
|
39
43
|
# return np array of image
|
|
40
44
|
return np.array(img)
|
|
41
45
|
|
|
@@ -248,7 +252,7 @@ def main() -> int:
|
|
|
248
252
|
|
|
249
253
|
# load and convert image to B&W
|
|
250
254
|
# flip image updown because Gcode and raster image coordinate system differ
|
|
251
|
-
narr = np.flipud(loadImage(args
|
|
255
|
+
narr = np.flipud(loadImage(args))
|
|
252
256
|
|
|
253
257
|
print(f'Area: {str(round(narr.shape[1] * args.pixelsize,2))}mm X {str(round(narr.shape[0] * args.pixelsize,2))}mm (XY)\n'
|
|
254
258
|
f' > pixelsize {args.pixelsize}mm^2, speed {args.speed}mm/min, maxpower {str(args.maxpower)},\n'
|
|
@@ -261,7 +265,7 @@ def main() -> int:
|
|
|
261
265
|
args.gcode.close()
|
|
262
266
|
with open(args.gcode.name, "r") as fgcode:
|
|
263
267
|
# flip to raster image coordinate system
|
|
264
|
-
img = np.flipud(gcode2image(Namespace(gcode = fgcode, showG0 = False, showOrigin = True, grid = True)))
|
|
268
|
+
img = np.flipud(gcode2image(Namespace(gcode = fgcode, resolution = args.pixelsize, showG0 = False, showOrigin = True, grid = True)))
|
|
265
269
|
|
|
266
270
|
# convert to image
|
|
267
271
|
img = Image.fromarray(img)
|
|
@@ -12,12 +12,12 @@ dynamic = ["version", "description"]
|
|
|
12
12
|
|
|
13
13
|
keywords = ["engraving", "laser", "image", "laser engraving", "PWM", "gcode"]
|
|
14
14
|
dependencies = [
|
|
15
|
-
"gcode2image >= 2.
|
|
15
|
+
"gcode2image >= 2.2",
|
|
16
16
|
"numpy >= 1.24.3",
|
|
17
17
|
"Pillow >= 9.5.0",
|
|
18
18
|
]
|
|
19
19
|
|
|
20
|
-
requires-python = ">=3.
|
|
20
|
+
requires-python = ">=3.7"
|
|
21
21
|
|
|
22
22
|
[project.scripts]
|
|
23
23
|
image2gcode = "image2gcode:main"
|
|
File without changes
|
|
File without changes
|