Browse Source

More barcodes sizes

master
squeaky otter 6 years ago
parent
commit
cabfa9db40
  1. 34
      barcode_utils.py
  2. 23
      templates/parts/_barcodes.jinja2

34
barcode_utils.py

@ -3,6 +3,13 @@ import barcode
from barcode.writer import ImageWriter
import os
BC_SIZES = {
"normal": (10.0, 10),
"medium": (5.0, 10),
"mini": (2.0, 8),
"mini_notext": (2.0, 0)
}
def generate_ean13(part_type, part_id, dir_out):
"""
@ -21,15 +28,26 @@ def generate_ean13(part_type, part_id, dir_out):
if len(barcode_str) > 13:
raise ValueError("barcode length exceded 13")
opts = dict(module_width=0.2, module_height=10.0, quiet_zone=1, font_size=10, text_distance=1)
dir_output = os.path.join(dir_out, "barcodes")
ean = barcode.get('ean13', barcode_str, writer=ImageWriter())
def generate(txt, size):
opts = dict(module_width=0.2, module_height=size[0], quiet_zone=1, font_size=size[1], text_distance=1)
ean = barcode.get('ean13', barcode_str, writer=ImageWriter())
dir_output = os.path.join(dir_out, "barcodes")
out = os.path.join(dir_output, _type, barcode_str)
if not os.path.isdir(os.path.join(dir_output, _type)):
os.makedirs(os.path.join(dir_output, _type))
out = os.path.join(dir_output, _type, "{0}_{1}".format(txt, barcode_str))
if not os.path.isdir(os.path.join(dir_output, _type)):
os.makedirs(os.path.join(dir_output, _type))
ean.save(out, opts)
filename = ean.save(out, opts)
generate('normal', BC_SIZES['normal'])
generate('medium', BC_SIZES['medium'])
generate('mini', BC_SIZES['mini'])
generate('mini_notext', BC_SIZES['mini_notext'])
return {"Barcode": barcode_str, "Out": dir_output, "Filename": filename, "Status": "OK", "Size": len(barcode_str)}
return {"Barcode": barcode_str,
"Out": dir_output,
"Status": "OK",
"Size": len(barcode_str),
"GeneratedSizes": ['normal', 'mini']}

23
templates/parts/_barcodes.jinja2

@ -1,4 +1,23 @@
{% if part.barcode_str %}
Full size (ean13):<br />
<img src="{{ url_for('get_uploads_stuff', stuff='barcodes/' + part.barcode_str[:2] + '/' + part.barcode_str + '.png') }}" alt="{{ part.barcode_str }}" />
<div class="row">
<div class="col-lg-3">
Full size (ean13):<br />
<img src="{{ url_for('get_uploads_stuff', stuff='barcodes/' + part.barcode_str[:2] + '/normal_' + part.barcode_str + '.png') }}" alt="{{ part.barcode_str }}" />
</div>
<div class="col-lg-3">
Medium size (ean13):<br />
<img src="{{ url_for('get_uploads_stuff', stuff='barcodes/' + part.barcode_str[:2] + '/medium_' + part.barcode_str + '.png') }}" alt="{{ part.barcode_str }}" />
</div>
<div class="col-lg-3">
Mini size (ean13):<br />
<img src="{{ url_for('get_uploads_stuff', stuff='barcodes/' + part.barcode_str[:2] + '/mini_' + part.barcode_str + '.png') }}" alt="{{ part.barcode_str }}" />
</div>
<div class="col-lg-3">
Mini without text size (ean13):<br />
<img src="{{ url_for('get_uploads_stuff', stuff='barcodes/' + part.barcode_str[:2] + '/mini_notext_' + part.barcode_str + '.png') }}" alt="{{ part.barcode_str }}" />
</div>
</div>
{% endif %}