image2gcode 2.2.2__py3-none-any.whl → 2.3.0__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.1
2
2
  Name: image2gcode
3
- Version: 2.2.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>
@@ -0,0 +1,6 @@
1
+ image2gcode.py,sha256=9E7e62vbc89wrCYN5K7nd2bfhoQSApQvBw15bZwIRgE,11364
2
+ image2gcode-2.3.0.dist-info/entry_points.txt,sha256=hQPqVKIhO8DUuxZtlnVCDygpjK9Ya_rv_L7O6Ks43H4,48
3
+ image2gcode-2.3.0.dist-info/LICENSE,sha256=ghSxQl_EUJUTiu712NkZkroJHvgOrR0j4CddAq8Y7Tc,1085
4
+ image2gcode-2.3.0.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
5
+ image2gcode-2.3.0.dist-info/METADATA,sha256=wEYGXrSjNWLRbN-DnWIhaDG0P5n2-UFG7aHI2M8SEE4,4952
6
+ image2gcode-2.3.0.dist-info/RECORD,,
image2gcode.py CHANGED
@@ -2,7 +2,7 @@
2
2
  """
3
3
  image2gcode: convert an image to gcode.
4
4
  """
5
- __version__ = "2.2.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(imagefile: str = None, showimage: bool = True):
21
+ def loadImage(args):
22
22
  """
23
- loadimage: load an image and convert it to b&w with white background
23
+ loadimage: load an image and convert it to b&w and white background
24
24
  """
25
25
 
26
- if imagefile:
26
+ if args.image:
27
27
  # add alpha channel
28
- img = Image.open(imagefile).convert("RGBA")
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
- # convert image to black&white (same size)
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.image.name,args.showimage))
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'
@@ -1,6 +0,0 @@
1
- image2gcode.py,sha256=DBXZxNlfd9HYdCrI5gl4dx9sU8DWVtirpOYQ5XwklqU,11224
2
- image2gcode-2.2.2.dist-info/entry_points.txt,sha256=hQPqVKIhO8DUuxZtlnVCDygpjK9Ya_rv_L7O6Ks43H4,48
3
- image2gcode-2.2.2.dist-info/LICENSE,sha256=ghSxQl_EUJUTiu712NkZkroJHvgOrR0j4CddAq8Y7Tc,1085
4
- image2gcode-2.2.2.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
5
- image2gcode-2.2.2.dist-info/METADATA,sha256=q1S9wbhEGCK_jW6DvbvC6QrFuM0cOETzEfNOaoldmVI,4952
6
- image2gcode-2.2.2.dist-info/RECORD,,