Skip to content

Commit

Permalink
Small update
Browse files Browse the repository at this point in the history
  • Loading branch information
KazukiPrzyborowski committed Nov 19, 2024
1 parent 2e684da commit f02c1d7
Show file tree
Hide file tree
Showing 19 changed files with 73 additions and 36 deletions.
4 changes: 3 additions & 1 deletion upcean/encode/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ def encode_binary_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48,
else:
upc_img = inimage[0]
upc_preimg = inimage[1]
if(imageoutlib not in imagelibsupport):
if(imageoutlib not in imagelibsupport and imageoutlib is not None):
imageoutlib = defaultdraw
if(imageoutlib is not None):
inimage = None
if(not re.findall("^([0-9]*[\\.]?[0-9])", str(resize)) or int(resize) < 1):
resize = 1
if(pilsupport and imageoutlib == "pillow"):
Expand Down
17 changes: 4 additions & 13 deletions upcean/encode/codabar.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,10 @@ def encode_codabar_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48
else:
upc_img = inimage[0]
upc_preimg = inimage[1]
imageoutlib = "pillow"
if pilsupport and isinstance(upc_img, ImageDraw.ImageDraw) and isinstance(upc_preimg, Image.Image):
imageoutlib = "pillow"
elif cairosupport and isinstance(upc_img, cairo.Context) and isinstance(upc_preimg, cairo.Surface):
imageoutlib = "cairo"
elif svgwritesupport and isinstance(upc_img, svgwrite.Drawing):
imageoutlib = "svgwrite"
elif(imageoutlib != "pillow" and imageoutlib != "cairo" and imageoutlib != "qahirah" and imageoutlib != "cairosvg" and imageoutlib != "svgwrite"):
imageoutlib = "pillow"
elif(not pilsupport and not cairosupport and not svgwritesupport):
return False
else:
return False
if(imageoutlib not in imagelibsupport and imageoutlib is not None):
imageoutlib = defaultdraw
if(imageoutlib is not None):
inimage = None
if(len(upc) < 1):
return False
if(barwidth[0] < 1):
Expand Down
4 changes: 3 additions & 1 deletion upcean/encode/code11.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ def encode_code11_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48,
else:
upc_img = inimage[0]
upc_preimg = inimage[1]
if(imageoutlib not in imagelibsupport):
if(imageoutlib not in imagelibsupport and imageoutlib is not None):
imageoutlib = defaultdraw
if(imageoutlib is not None):
inimage = None
if(len(upc) < 1):
return False
if(not re.findall("([0-9\\-]+)", upc)):
Expand Down
8 changes: 6 additions & 2 deletions upcean/encode/code128.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ def encode_code128_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48
else:
upc_img = inimage[0]
upc_preimg = inimage[1]
if(imageoutlib not in imagelibsupport):
if(imageoutlib not in imagelibsupport and imageoutlib is not None):
imageoutlib = defaultdraw
if(imageoutlib is not None):
inimage = None
if(len(upc) % 2):
return False
if(len(upc) < 8):
Expand Down Expand Up @@ -703,8 +705,10 @@ def encode_code128old_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=
else:
upc_img = inimage[0]
upc_preimg = inimage[1]
if(imageoutlib not in imagelibsupport):
if(imageoutlib not in imagelibsupport and imageoutlib is not None):
imageoutlib = defaultdraw
if(imageoutlib is not None):
inimage = None
if(len(upc) % 2):
return False
if(len(upc) < 8):
Expand Down
4 changes: 3 additions & 1 deletion upcean/encode/code32.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ def encode_code32_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48,
else:
upc_img = inimage[0]
upc_preimg = inimage[1]
if(imageoutlib not in imagelibsupport):
if(imageoutlib not in imagelibsupport and imageoutlib is not None):
imageoutlib = defaultdraw
if(imageoutlib is not None):
inimage = None
if(len(upc) < 1):
return False
if(not re.findall("([0-9a-zB-DF-HJ-NP-Z\\-\\.\\$\\/\\+% ]+)", upc)):
Expand Down
8 changes: 6 additions & 2 deletions upcean/encode/code39.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ def encode_code39_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48,
else:
upc_img = inimage[0]
upc_preimg = inimage[1]
if(imageoutlib not in imagelibsupport):
if(imageoutlib not in imagelibsupport and imageoutlib is not None):
imageoutlib = defaultdraw
if(imageoutlib is not None):
inimage = None
if(len(upc) < 1):
return False
if(not re.findall("([0-9a-zA-Z\\-\\.\\$\\/\\+% ]+)", upc)):
Expand Down Expand Up @@ -426,8 +428,10 @@ def encode_code39extended_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barhei
else:
upc_img = inimage[0]
upc_preimg = inimage[1]
if(imageoutlib not in imagelibsupport):
if(imageoutlib not in imagelibsupport and imageoutlib is not None):
imageoutlib = defaultdraw
if(imageoutlib is not None):
inimage = None
if(len(upc) < 1):
return False
if(not re.findall("([0-9a-zA-Z\\-\\.\\$\\/\\+% ]+)", upc)):
Expand Down
8 changes: 6 additions & 2 deletions upcean/encode/code93.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ def encode_code93_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48,
else:
upc_img = inimage[0]
upc_preimg = inimage[1]
if(imageoutlib not in imagelibsupport):
if(imageoutlib not in imagelibsupport and imageoutlib is not None):
imageoutlib = defaultdraw
if(imageoutlib is not None):
inimage = None
if(len(upc) < 1):
return False
if(not re.findall("([0-9a-zA-Z\\-\\.\\$\\/\\+% ]+)", upc)):
Expand Down Expand Up @@ -424,8 +426,10 @@ def encode_code93extended_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barhei
else:
upc_img = inimage[0]
upc_preimg = inimage[1]
if(imageoutlib not in imagelibsupport):
if(imageoutlib not in imagelibsupport and imageoutlib is not None):
imageoutlib = defaultdraw
if(imageoutlib is not None):
inimage = None
if(len(upc) < 1):
return False
if(not re.findall("([0-9a-zA-Z\\-\\.\\$\\/\\+% ]+)", upc)):
Expand Down
4 changes: 3 additions & 1 deletion upcean/encode/ean13.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ def encode_ean13_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48,
upc_preimg = inimage[1]
upc_pieces = None
supplement = None
if(imageoutlib not in imagelibsupport):
if(imageoutlib not in imagelibsupport and imageoutlib is not None):
imageoutlib = defaultdraw
if(imageoutlib is not None):
inimage = None
if(re.findall("([0-9]+)([ |\\|]{1})([0-9]{2})$", upc)):
upc_pieces = re.findall("([0-9]+)([ |\\|]{1})([0-9]{2})$", upc)
upc_pieces = upc_pieces[0]
Expand Down
4 changes: 3 additions & 1 deletion upcean/encode/ean2.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ def encode_ean2_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48, 5
else:
upc_img = inimage[0]
upc_preimg = inimage[1]
if(imageoutlib not in imagelibsupport):
if(imageoutlib not in imagelibsupport and imageoutlib is not None):
imageoutlib = defaultdraw
if(imageoutlib is not None):
inimage = None
if(len(upc) > 2 or len(upc) < 2):
return False
upc_matches = re.findall("(\\d{2})", upc)
Expand Down
4 changes: 3 additions & 1 deletion upcean/encode/ean5.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ def encode_ean5_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48, 5
else:
upc_img = inimage[0]
upc_preimg = inimage[1]
if(imageoutlib not in imagelibsupport):
if(imageoutlib not in imagelibsupport and imageoutlib is not None):
imageoutlib = defaultdraw
if(imageoutlib is not None):
inimage = None
if(len(upc) > 5 or len(upc) < 5):
return False
upc_matches = re.findall("(\\d{5})", upc)
Expand Down
4 changes: 3 additions & 1 deletion upcean/encode/ean8.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ def encode_ean8_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48, 5
upc_preimg = inimage[1]
upc_pieces = None
supplement = None
if(imageoutlib not in imagelibsupport):
if(imageoutlib not in imagelibsupport and imageoutlib is not None):
imageoutlib = defaultdraw
if(imageoutlib is not None):
inimage = None
if(re.findall("([0-9]+)([ |\\|]{1})([0-9]{2})$", upc)):
upc_pieces = re.findall("([0-9]+)([ |\\|]{1})([0-9]{2})$", upc)
upc_pieces = upc_pieces[0]
Expand Down
4 changes: 3 additions & 1 deletion upcean/encode/itf.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ def encode_itf_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48, 54
else:
upc_img = inimage[0]
upc_preimg = inimage[1]
if(imageoutlib not in imagelibsupport):
if(imageoutlib not in imagelibsupport and imageoutlib is not None):
imageoutlib = defaultdraw
if(imageoutlib is not None):
inimage = None
if(len(upc) % 2):
return False
if(len(upc) < 6):
Expand Down
4 changes: 3 additions & 1 deletion upcean/encode/itf14.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ def encode_itf14_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48,
else:
upc_img = inimage[0]
upc_preimg = inimage[1]
if(imageoutlib not in imagelibsupport):
if(imageoutlib not in imagelibsupport and imageoutlib is not None):
imageoutlib = defaultdraw
if(imageoutlib is not None):
inimage = None
if(len(upc) % 2):
return False
if(len(upc) < 6):
Expand Down
4 changes: 3 additions & 1 deletion upcean/encode/msi.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ def encode_msi_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48, 54
else:
upc_img = inimage[0]
upc_preimg = inimage[1]
if(imageoutlib not in imagelibsupport):
if(imageoutlib not in imagelibsupport and imageoutlib is not None):
imageoutlib = defaultdraw
if(imageoutlib is not None):
inimage = None
if(len(upc) < 1):
return False
if(not re.findall("([0-9]+)", upc)):
Expand Down
4 changes: 3 additions & 1 deletion upcean/encode/plessey.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ def encode_plessey_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48
else:
upc_img = inimage[0]
upc_preimg = inimage[1]
if(imageoutlib not in imagelibsupport):
if(imageoutlib not in imagelibsupport and imageoutlib is not None):
imageoutlib = defaultdraw
if(imageoutlib is not None):
inimage = None
if(len(upc) < 1):
return False
if(not re.findall("([0-9a-fA-F]+)", upc)):
Expand Down
4 changes: 3 additions & 1 deletion upcean/encode/stf.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ def encode_stf_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48, 54
else:
upc_img = inimage[0]
upc_preimg = inimage[1]
if(imageoutlib not in imagelibsupport):
if(imageoutlib not in imagelibsupport and imageoutlib is not None):
imageoutlib = defaultdraw
if(imageoutlib is not None):
inimage = None
if(len(upc) % 2):
return False
if(len(upc) < 6):
Expand Down
8 changes: 6 additions & 2 deletions upcean/encode/upca.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ def encode_upca_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48, 5
upc_preimg = inimage[1]
upc_pieces = None
supplement = None
if(imageoutlib not in imagelibsupport):
if(imageoutlib not in imagelibsupport and imageoutlib is not None):
imageoutlib = defaultdraw
if(imageoutlib is not None):
inimage = None
if(re.findall("([0-9]+)([ |\\|]{1})([0-9]{2})$", upc)):
upc_pieces = re.findall("([0-9]+)([ |\\|]{1})([0-9]{2})$", upc)
upc_pieces = upc_pieces[0]
Expand Down Expand Up @@ -510,8 +512,10 @@ def encode_upcaean_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48
upc_preimg = inimage[1]
upc_pieces = None
supplement = None
if(imageoutlib not in imagelibsupport):
if(imageoutlib not in imagelibsupport and imageoutlib is not None):
imageoutlib = defaultdraw
if(imageoutlib is not None):
inimage = None
if(re.findall("([0-9]+)([ |\\|]{1})([0-9]{2})$", upc)):
upc_pieces = re.findall("([0-9]+)([ |\\|]{1})([0-9]{2})$", upc)
upc_pieces = upc_pieces[0]
Expand Down
8 changes: 6 additions & 2 deletions upcean/encode/upcavar.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ def encode_upcavar_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48
upc_preimg = inimage[1]
upc_pieces = None
supplement = None
if(imageoutlib not in imagelibsupport):
if(imageoutlib not in imagelibsupport and imageoutlib is not None):
imageoutlib = defaultdraw
if(imageoutlib is not None):
inimage = None
if(re.findall("([0-9]+)([ |\\|]{1})([0-9]{2})$", upc)):
upc_pieces = re.findall("([0-9]+)([ |\\|]{1})([0-9]{2})$", upc)
upc_pieces = upc_pieces[0]
Expand Down Expand Up @@ -521,8 +523,10 @@ def encode_upcaeanvar_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=
upc_preimg = inimage[1]
upc_pieces = None
supplement = None
if(imageoutlib not in imagelibsupport):
if(imageoutlib not in imagelibsupport and imageoutlib is not None):
imageoutlib = defaultdraw
if(imageoutlib is not None):
inimage = None
if(re.findall("([0-9]+)([ |\\|]{1})([0-9]{2})$", upc)):
upc_pieces = re.findall("([0-9]+)([ |\\|]{1})([0-9]{2})$", upc)
upc_pieces = upc_pieces[0]
Expand Down
4 changes: 3 additions & 1 deletion upcean/encode/upce.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ def encode_upce_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48, 5
upc_preimg = inimage[1]
upc_pieces = None
supplement = None
if(imageoutlib not in imagelibsupport):
if(imageoutlib not in imagelibsupport and imageoutlib is not None):
imageoutlib = defaultdraw
if(imageoutlib is not None):
inimage = None
if(re.findall("([0-9]+)([ |\\|]{1})([0-9]{2})$", upc)):
upc_pieces = re.findall("([0-9]+)([ |\\|]{1})([0-9]{2})$", upc)
upc_pieces = upc_pieces[0]
Expand Down

0 comments on commit f02c1d7

Please sign in to comment.