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 8454426 commit 2e684da
Show file tree
Hide file tree
Showing 26 changed files with 248 additions and 1,417 deletions.
59 changes: 30 additions & 29 deletions upcean/encode/barcode.py

Large diffs are not rendered by default.

82 changes: 9 additions & 73 deletions upcean/encode/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
pgmagicksupport = upcean.support.check_for_pgmagick()
cv2support = upcean.support.check_for_cv2()
skimagesupport = upcean.support.check_for_skimage()
imagelibsupport = upcean.support.imagelibsupport
defaultdraw = upcean.support.defaultdraw
if(pilsupport or pillowsupport):
import upcean.predraw.prepil
Expand Down Expand Up @@ -81,7 +82,7 @@ def get_binary_barcode_size(upc, resize=1, shiftxy=(0, 0), barheight=(48, 54), b
return {'without_shift': reswoshift, 'with_shift': reswshift}


def encode_binary_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48, 54), barwidth=(1, 1), barcolor=((0, 0, 0), (0, 0, 0), (255, 255, 255)), hideinfo=(False, False, False)):
def encode_binary_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48, 54), barwidth=(1, 1), barcolor=((0, 0, 0), (0, 0, 0), (255, 255, 255)), hideinfo=(False, False, False), imageoutlib=None):
hidesn = hideinfo[0]
hidecd = hideinfo[1]
hidetext = hideinfo[2]
Expand All @@ -96,33 +97,8 @@ def encode_binary_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48,
else:
upc_img = inimage[0]
upc_preimg = inimage[1]
imageoutlib = None
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 qahirahsupport and isinstance(upc_img, qah.Context) and isinstance(upc_preimg, qah.Surface):
imageoutlib = "qahirah"
elif svgwritesupport and isinstance(upc_img, svgwrite.Drawing):
imageoutlib = "svgwrite"
elif wandsupport and isinstance(upc_img, wImage):
imageoutlib = "wand"
elif magicksupport and isinstance(upc_img, PythonMagick.Image):
imageoutlib = "magick"
elif pgmagicksupport and isinstance(upc_img, pgmagick.Image):
imageoutlib = "pgmagick"
elif cv2support and upc_preimg=="cv2":
imageoutlib = "cv2"
elif skimagesupport and upc_preimg=="skimage":
imageoutlib = "skimage"
elif(imageoutlib != "pillow" and imageoutlib != "cairo" and imageoutlib != "qahirah" and imageoutlib != "cairosvg" and imageoutlib != "svgwrite" and imageoutlib != "wand" and imageoutlib != "magick" and imageoutlib != "pgmagick" and imageoutlib != "cv2" and imageoutlib != "skimage" and inimage != "none" and inimage is not None):
imageoutlib = None
elif(inimage == "none" or inimage is None):
imageoutlib = None
elif(not pilsupport and not cairosupport and not svgwritesupport):
return False
else:
return False
if(imageoutlib not in imagelibsupport):
imageoutlib = defaultdraw
if(not re.findall("^([0-9]*[\\.]?[0-9])", str(resize)) or int(resize) < 1):
resize = 1
if(pilsupport and imageoutlib == "pillow"):
Expand Down Expand Up @@ -189,56 +165,16 @@ def draw_binary_barcode(upc, resize=1, barheight=(48, 54), barwidth=(1, 1), barc
barheightadd = barheight[0] + 6
else:
barheightadd = barheight[1]
if(not pilsupport and imageoutlib == "pillow"):
imageoutlib = "svgwrite"
if(not cairosupport and (imageoutlib == "cairo" or imageoutlib == "cairosvg")):
imageoutlib = "svgwrite"
if(not qahirahsupport and imageoutlib == "qahirah"):
imageoutlib = "svgwrite"
if(not cairosupport and imageoutlib == "cairosvg"):
imageoutlib = "svgwrite"
if(not svgwritesupport and imageoutlib == "svgwrite"):
imageoutlib = "svgwrite"
if(not wandsupport and imageoutlib == "wand"):
imageoutlib = "svgwrite"
if(not magicksupport and imageoutlib == "magick"):
imageoutlib = "svgwrite"
if(not pgmagicksupport and imageoutlib == "pgmagick"):
imageoutlib = "svgwrite"
if(not cv2support and imageoutlib == "cv2"):
imageoutlib = "svgwrite"
if(not skimagesupport and imageoutlib == "skimage"):
imageoutlib = "svgwrite"
if(imageoutlib != "pillow" and imageoutlib != "cairo" and imageoutlib != "qahirah" and imageoutlib != "cairosvg" and imageoutlib != "wand" and imageoutlib != "magick" and imageoutlib != "pgmagick" and imageoutlib != "cv2" and imageoutlib != "skimage" and imageoutlib != "svgwrite"):
imageoutlib = "svgwrite"
if(imageoutlib not in imagelibsupport):
imageoutlib = defaultdraw
upc_size_add = len([item for sublist in upc['code'] for item in sublist]) * (barwidth[0] * int(resize))
upc_img, upc_preimg = upcean.predraw.new_image_surface(upc_size_add, (barheightadd + (upc['heightadd'] * barwidth[1])) * int(resize), barcolor[2], imageoutlib)
imgout = encode_binary_barcode([upc_img, upc_preimg], upc, resize, (0, 0), barheight, barwidth, barcolor, hideinfo)
imgout = encode_binary_barcode([upc_img, upc_preimg], upc, resize, (0, 0), barheight, barwidth, barcolor, hideinfo, imageoutlib)
return [upc_img, upc_preimg, imageoutlib]

def create_binary_barcode(upc, outfile="./binary.png", resize=1, barheight=(48, 54), barwidth=(1, 1), barcolor=((0, 0, 0), (0, 0, 0), (255, 255, 255)), hideinfo=(False, False, False), imagecomment=None, imageoutlib=defaultdraw):
if(not pilsupport and imageoutlib == "pillow"):
imageoutlib = "svgwrite"
if(not cairosupport and (imageoutlib == "cairo" or imageoutlib == "cairosvg")):
imageoutlib = "svgwrite"
if(not qahirahsupport and imageoutlib == "qahirah"):
imageoutlib = "svgwrite"
if(not cairosupport and imageoutlib == "cairosvg"):
imageoutlib = "svgwrite"
if(not svgwritesupport and imageoutlib == "svgwrite"):
imageoutlib = "svgwrite"
if(not wandsupport and imageoutlib == "wand"):
imageoutlib = "svgwrite"
if(not magicksupport and imageoutlib == "magick"):
imageoutlib = "svgwrite"
if(not pgmagicksupport and imageoutlib == "pgmagick"):
imageoutlib = "svgwrite"
if(not cv2support and imageoutlib == "cv2"):
imageoutlib = "svgwrite"
if(not skimagesupport and imageoutlib == "skimage"):
imageoutlib = "svgwrite"
if(imageoutlib != "pillow" and imageoutlib != "cairo" and imageoutlib != "qahirah" and imageoutlib != "cairosvg" and imageoutlib != "wand" and imageoutlib != "magick" and imageoutlib != "pgmagick" and imageoutlib != "cv2" and imageoutlib != "skimage" and imageoutlib != "svgwrite"):
imageoutlib = "svgwrite"
if(imageoutlib not in imagelibsupport):
imageoutlib = defaultdraw
if(outfile is None):
if(imageoutlib == "cairosvg"):
oldoutfile = None
Expand Down
29 changes: 5 additions & 24 deletions upcean/encode/codabar.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
pgmagicksupport = upcean.support.check_for_pgmagick()
cv2support = upcean.support.check_for_cv2()
skimagesupport = upcean.support.check_for_skimage()
imagelibsupport = upcean.support.imagelibsupport
defaultdraw = upcean.support.defaultdraw
if(pilsupport or pillowsupport):
import upcean.predraw.prepil
Expand Down Expand Up @@ -92,7 +93,7 @@ def get_codabar_barcode_size(upc, resize=1, shiftxy=(0, 0), barheight=(48, 54),
return {'without_shift': reswoshift, 'with_shift': reswshift}


def encode_codabar_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48, 54), barwidth=(1, 1), barcolor=((0, 0, 0), (0, 0, 0), (255, 255, 255)), hideinfo=(False, False, False)):
def encode_codabar_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48, 54), barwidth=(1, 1), barcolor=((0, 0, 0), (0, 0, 0), (255, 255, 255)), hideinfo=(False, False, False), imageoutlib=None):
upc = str(upc)
hidesn = hideinfo[0]
hidecd = hideinfo[1]
Expand Down Expand Up @@ -329,32 +330,12 @@ def draw_codabar_barcode(upc, resize=1, barheight=(48, 54), barwidth=(1, 1), bar
upc_size_add = ((bcsize9 * 9) + (bcsize10 * 10) +
(bcsize12 * 12) + len(upc_matches) - 1) * barwidth[0]
upc_img, upc_preimg = upcean.predraw.new_image_surface(((40 * barwidth[0]) + upc_size_add) * int(resize), (barheightadd + (9 * barwidth[1])) * int(resize), barcolor[2], imageoutlib)
imgout = encode_codabar_barcode([upc_img, upc_preimg], upc, resize, (0, 0), barheight, barwidth, barcolor, hideinfo)
imgout = encode_codabar_barcode([upc_img, upc_preimg], upc, resize, (0, 0), barheight, barwidth, barcolor, hideinfo, imageoutlib)
return [upc_img, upc_preimg, imageoutlib]

def create_codabar_barcode(upc, outfile="./codabar.png", resize=1, barheight=(48, 54), barwidth=(1, 1), barcolor=((0, 0, 0), (0, 0, 0), (255, 255, 255)), hideinfo=(False, False, False), imagecomment=None, imageoutlib=defaultdraw):
if(not pilsupport and imageoutlib == "pillow"):
imageoutlib = "svgwrite"
if(not cairosupport and (imageoutlib == "cairo" or imageoutlib == "cairosvg")):
imageoutlib = "svgwrite"
if(not qahirahsupport and imageoutlib == "qahirah"):
imageoutlib = "svgwrite"
if(not cairosupport and imageoutlib == "cairosvg"):
imageoutlib = "svgwrite"
if(not svgwritesupport and imageoutlib == "svgwrite"):
imageoutlib = "svgwrite"
if(not wandsupport and imageoutlib == "wand"):
imageoutlib = "svgwrite"
if(not magicksupport and imageoutlib == "magick"):
imageoutlib = "svgwrite"
if(not pgmagicksupport and imageoutlib == "pgmagick"):
imageoutlib = "svgwrite"
if(not cv2support and imageoutlib == "cv2"):
imageoutlib = "svgwrite"
if(not skimagesupport and imageoutlib == "skimage"):
imageoutlib = "svgwrite"
if(imageoutlib != "pillow" and imageoutlib != "cairo" and imageoutlib != "qahirah" and imageoutlib != "cairosvg" and imageoutlib != "wand" and imageoutlib != "magick" and imageoutlib != "pgmagick" and imageoutlib != "cv2" and imageoutlib != "skimage" and imageoutlib != "svgwrite"):
imageoutlib = "svgwrite"
if(imageoutlib not in imagelibsupport):
imageoutlib = defaultdraw
if(outfile is None):
if(imageoutlib == "cairosvg"):
oldoutfile = None
Expand Down
58 changes: 7 additions & 51 deletions upcean/encode/code11.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
pgmagicksupport = upcean.support.check_for_pgmagick()
cv2support = upcean.support.check_for_cv2()
skimagesupport = upcean.support.check_for_skimage()
imagelibsupport = upcean.support.imagelibsupport
defaultdraw = upcean.support.defaultdraw
if(pilsupport or pillowsupport):
import upcean.predraw.prepil
Expand Down Expand Up @@ -90,7 +91,7 @@ def get_code11_barcode_size(upc, resize=1, shiftxy=(0, 0), barheight=(48, 54), b
return {'without_shift': reswoshift, 'with_shift': reswshift}


def encode_code11_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48, 54), barwidth=(1, 1), barcolor=((0, 0, 0), (0, 0, 0), (255, 255, 255)), hideinfo=(False, False, False)):
def encode_code11_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48, 54), barwidth=(1, 1), barcolor=((0, 0, 0), (0, 0, 0), (255, 255, 255)), hideinfo=(False, False, False), imageoutlib=None):
upc = str(upc)
hidesn = hideinfo[0]
hidecd = hideinfo[1]
Expand All @@ -106,33 +107,8 @@ def encode_code11_barcode(inimage, upc, resize=1, shiftxy=(0, 0), barheight=(48,
else:
upc_img = inimage[0]
upc_preimg = inimage[1]
imageoutlib = None
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 qahirahsupport and isinstance(upc_img, qah.Context) and isinstance(upc_preimg, qah.Surface):
imageoutlib = "qahirah"
elif svgwritesupport and isinstance(upc_img, svgwrite.Drawing):
imageoutlib = "svgwrite"
elif wandsupport and isinstance(upc_img, wImage):
imageoutlib = "wand"
elif magicksupport and isinstance(upc_img, PythonMagick.Image):
imageoutlib = "magick"
elif pgmagicksupport and isinstance(upc_img, pgmagick.Image):
imageoutlib = "pgmagick"
elif cv2support and upc_preimg=="cv2":
imageoutlib = "cv2"
elif skimagesupport and upc_preimg=="skimage":
imageoutlib = "skimage"
elif(imageoutlib != "pillow" and imageoutlib != "cairo" and imageoutlib != "qahirah" and imageoutlib != "cairosvg" and imageoutlib != "svgwrite" and imageoutlib != "wand" and imageoutlib != "magick" and imageoutlib != "pgmagick" and imageoutlib != "cv2" and imageoutlib != "skimage" and inimage != "none" and inimage is not None):
imageoutlib = None
elif(inimage == "none" or inimage is None):
imageoutlib = None
elif(not pilsupport and not cairosupport and not svgwritesupport):
return False
else:
return False
if(imageoutlib not in imagelibsupport):
imageoutlib = defaultdraw
if(len(upc) < 1):
return False
if(not re.findall("([0-9\\-]+)", upc)):
Expand Down Expand Up @@ -315,32 +291,12 @@ def draw_code11_barcode(upc, resize=1, barheight=(48, 54), barwidth=(1, 1), barc
upc_preimg = StringIO()
upc_img = svgwrite.Drawing(upc_preimg, profile='full', size=(((34 * barwidth[0]) + upc_size_add) * int(resize), (barheightadd + (9 * barwidth[1])) * int(resize)))
upc_preimg.close()
imgout = encode_code11_barcode([upc_img, upc_preimg], upc, resize, (0, 0), barheight, barwidth, barcolor, hideinfo)
imgout = encode_code11_barcode([upc_img, upc_preimg], upc, resize, (0, 0), barheight, barwidth, barcolor, hideinfo, imageoutlib)
return [upc_img, upc_preimg, imageoutlib]

def create_code11_barcode(upc, outfile="./code11.png", resize=1, barheight=(48, 54), barwidth=(1, 1), barcolor=((0, 0, 0), (0, 0, 0), (255, 255, 255)), hideinfo=(False, False, False), imagecomment=None, imageoutlib=defaultdraw):
if(not pilsupport and imageoutlib == "pillow"):
imageoutlib = "svgwrite"
if(not cairosupport and (imageoutlib == "cairo" or imageoutlib == "cairosvg")):
imageoutlib = "svgwrite"
if(not qahirahsupport and imageoutlib == "qahirah"):
imageoutlib = "svgwrite"
if(not cairosupport and imageoutlib == "cairosvg"):
imageoutlib = "svgwrite"
if(not svgwritesupport and imageoutlib == "svgwrite"):
imageoutlib = "svgwrite"
if(not wandsupport and imageoutlib == "wand"):
imageoutlib = "svgwrite"
if(not magicksupport and imageoutlib == "magick"):
imageoutlib = "svgwrite"
if(not pgmagicksupport and imageoutlib == "pgmagick"):
imageoutlib = "svgwrite"
if(not cv2support and imageoutlib == "cv2"):
imageoutlib = "svgwrite"
if(not skimagesupport and imageoutlib == "skimage"):
imageoutlib = "svgwrite"
if(imageoutlib != "pillow" and imageoutlib != "cairo" and imageoutlib != "qahirah" and imageoutlib != "cairosvg" and imageoutlib != "wand" and imageoutlib != "magick" and imageoutlib != "pgmagick" and imageoutlib != "cv2" and imageoutlib != "skimage" and imageoutlib != "svgwrite"):
imageoutlib = "svgwrite"
if(imageoutlib not in imagelibsupport):
imageoutlib = defaultdraw
if(outfile is None):
if(imageoutlib == "cairosvg"):
oldoutfile = None
Expand Down
Loading

0 comments on commit 2e684da

Please sign in to comment.