㊙️ Create standard barcodes with Python. No external dependencies. 100% Organic Python.

Overview

python-barcode

CI status Build coverage documentation version on pypi downloads licence

python-barcode provides a simple way to create barcodes in Python.

There are no external dependencies when generating SVG files. Pillow is required for generating images (e.g.: PNGs).

Support Python 3.6 to 3.9.

python-barcode

Documentation

Full documentation is published at http://python-barcode.rtfd.io/

Licence

python-barcode is licensed under the MIT licence. See LICENCE for details.

Comments
  • Unable to import barcode

    Unable to import barcode

    i already install barcode module from official python site like "pip install python-barcode". but whenever i write a code on text editor like 1-Visual Studio 2-SubLime 3-Pycharm theirs an error pop up and it's says "Unable to import 'barcode' pylint(input-error)[1,1]"

    question 
    opened by Soumalya-Mondal 11
  • Cannot save as png after packaging into exe file

    Cannot save as png after packaging into exe file

    微信截图_20200426105205

    Traceback (most recent call last):
      File "site-packages\PIL\ImageFont.py", line 186, in __init__
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 9: ordinal not in range(128)
    

    This error occurs under python3.6, how to solve it

    opened by Yinjiafeng 10
  • TypeError running # Example with PNG in usage guide

    TypeError running # Example with PNG in usage guide

    I'm running Python 3.5.5. A subsection of the usage guide:

    import barcode
    from barcode.writer import ImageWriter
    EAN = barcode.get_barcode_class('code128')
    ean = EAN(u'5901234123457', writer=ImageWriter())
    

    ...gives me the following error:

    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    <ipython-input-67-21778fac1b87> in <module>()
    ----> 1 ean = EAN(u'5901234123457', writer=ImageWriter())
    
    TypeError: 'NoneType' object is not callable
    

    Am I doing something wrong?

    opened by DannyDannyDanny 9
  • Pillow dreprecation warning about ImageFont.getsize

    Pillow dreprecation warning about ImageFont.getsize

    Hello!

    Pillow 9.2.0 is installed in my virtualenv and when I use python-barcode there is a deprecation warning about the method ImageFont.getsize.

    virtualenv/lib/python3.9/site-packages/barcode/writer.py:441: DeprecationWarning: getsize is deprecated and will be removed in Pillow 10 (2023-07-01). Use getbbox or getlength instead.
        width, height = font.getsize(subtext)
    

    Since the version 9.2, getsize is deprecated and replaced by getlength. See the PR https://github.com/python-pillow/Pillow/pull/6381.

    opened by brvoisin 7
  • Using 'raw' without using 'save' gives no output

    Using 'raw' without using 'save' gives no output

    I think the title explains it all.

    If I try to use .raw to server an SVG barcode without using .save first, I get an empty output...

    Example: Trying to serve this in my django project:

    class APIBarcode(View):
    
        def get(self, request, *args, **kwargs):
            uuid = request.GET.get('uuid')
            C39 = barcode.get_barcode_class('code39')
            toserve = C39(uuid)
            toserve.save('c39code')
            return HttpResponse(toserve.raw, content_type="image/svg+xml")
    

    Gives the following output: image

    But serving this:

    class APIBarcode(View):
    
        def get(self, request, *args, **kwargs):
            uuid = request.GET.get('uuid')
            C39 = barcode.get_barcode_class('code39')
            toserve = C39(uuid)
            # toserve.save('c39code')
            return HttpResponse(toserve.raw, content_type="image/svg+xml")
    

    Gives the following output:

    image

    If someone can point me to where I should be looking I would gladly attempt to fix it!

    opened by sharifanani 6
  • fix wrong bar width in ImageWriter

    fix wrong bar width in ImageWriter

    fixes #79 and maybe others?

    This might seem trivial, but took me a couple of minutes to track it down. I'm attaching false-colored images for reference. Please pay attention to the final white bar in particular. SvgWriter is not affected as the rectangle implementation is different.

    DPI 300

    before before

    after after

    DPI 100

    before

    after

    opened by fostermaier 5
  • Fix issue #171 calculating checksum before any controls

    Fix issue #171 calculating checksum before any controls

    Moved super().__init__ before calling _calculate_checksum() to check if the string contains any letters to prevent value errors that can happen when calculating checksum. I tested the new version with the input 0132354187 and the produced barcode before and after the commit is the same as 9780132352.

    opened by canklot 5
  • Adds support for longer guard bar to EAN13 and EAN8

    Adds support for longer guard bar to EAN13 and EAN8

    This PR tries to partially solve Issue #11

    Adds a parameter to both classes that controls if we want longer guard bars and then while building the code to be generated, use "G" instead of "1" in those places we will need to have a longer bar.

    During the write, interpret every "G" the same as "1" but add an height factor to the mod list. To avoid changing the entire code base to add a height parameter, set the self.module_height for every bar generated.

    opened by Governa 5
  • Bug in new version in generate?

    Bug in new version in generate?

    In the new version if I try to use:

    import barcode
    barcode.generate('ean13', '123455559121112')
    

    I get an error TypeError: get() got an unexpected keyword argument 'writer_options' I get this both in version 0.12 and 0.13. Is there something I can do about this, or is this a bug?

    bug 
    opened by RosanneZe 5
  • EAN-13/GTIN-13 barcodes don't contain grouping

    EAN-13/GTIN-13 barcodes don't contain grouping

    According to the specs I've found, GTIN-13/EAN-13 barcodes must contain the grouping most commonly found on printed barcodes, i.e. the first character is outside of the code area, and the remainder is in two groups with elongated bars separating the groups.

    Is there any support for this planned? How about the '>' mark for silent areas?

    opened by jfinkhaeuser 5
  • Fix deprecation warning about ImageFont.getsize

    Fix deprecation warning about ImageFont.getsize

    python-barcode/barcode/writer.py:441: DeprecationWarning: getsize is deprecated and will be removed in Pillow 10 (2023-07-01). Use getbbox or getlength instead. width, height = font.getsize(subtext)

    ImageFont.getsize is deprecated since the version 9.2 of Pillow. We use anchor instead of computing the right position to have an aligned text.

    It is related to the issue #163. The solution was suggested by @nulano (contributor of Pillow).

    opened by brvoisin 4
  • Basic support for MSI / Plessey

    Basic support for MSI / Plessey

    also allows encoding of strings and bytestrings (allows encoding any symbol) by converting them to int ; in this case, string representation is shown in human-readable string

    opened by petaflot 5
  • Implement PZN8

    Implement PZN8

    Implement PZN8 code generation. Fixes #167.

    • keeping PZN for PZN7, implementing PZN8 for PZN8
    • checksum is commonly part of the PZN* code. Hence, we verify or append the checksum based on the length of the supplied PZN7 or PZN8 code.
    • explicit error messages concerning code length for both classes respectively
    • different checksum calculation for PZN8. see http://www.pruefziffernberechnung.de/P/PZN.shtml

    usage

    check code length

    >>> PZN('12345678')
    barcode.errors.NumberOfDigitsError: PZN7 must have 6 digits (excluding checksum) or 7 digits (including checksum), not 8.
    >>> PZN8('123456789')
    barcode.errors.NumberOfDigitsError: PZN8 must have 7 digits (excluding checksum) or 8 digits (including checksum), not 9.
    

    auto-append checksum

    >>> PZN('123456')
    <PZN7('PZN-1234562')>
    >>> PZN8('1234567')
    <PZN8('PZN-12345678')>
    

    verify checksum if supplied

    >>> PZN('1234568')
    barcode.errors.BarcodeError: Checksum (last digit) is not valid for the supplied PZN7 code.
    >>> PZN('1234562')
    <PZN7('PZN-1234562')>
    

    resources (mostly german)

    • checksum details http://www.pruefziffernberechnung.de/P/PZN.shtml
    • official specification https://www.ifaffm.de/de/ifa-codingsystem/codierung-pzn-code_39.html

    samples

    PZN7: https://barcode.tec-it.com/de/Health_PZN7 pzn7

    PZN8: https://www.softmatic.com/de/barcode-code-pzn.html pzn8

    opened by fostermaier 1
  • UPC/UPCA final output doesn't include guard bars

    UPC/UPCA final output doesn't include guard bars

    I'm being told (not a barcode format specialist) that the standard presentation for a UPC/UPCA code should look like this:

    image

    If I generate this barcode using the following code however, I get this:

    image

    Issues:

    Added "F" at the end?

    Any way to turn this off?

    Guardbars not displayed

    As I seem to understand, the standard/typical presentation for those code should include guardbars. I tried adding the "guardbars" keywords but it seems the UPC class doesn't accept that argument.

    Code:

    python-barcode create 686254053919 upc

    Also generated as part of a server-side rendering, with same result:

    UPCA(str(value["code"]), writer=SVGWriter(), guardbars=True).write(file)

    opened by logikonabstractions 1
  • Text placement in ImageWriter

    Text placement in ImageWriter

    I believe text is incorrectly located in barcode when using ImageWriter as of 0.14.0. This is mainly due to a wrong computation of text height which is a very common problem due to the fact that total height for a font is different from the height of rendered glyphs for most of the ascii characters.

    Attached is a proposed patch to place text correctly. Note that because most of the time a barcode is followed by a text with capital letters, the blank space at the bottom is more that 1mm (which would be nice to set as an option). It should be closer to 1mm when using letters that goes below the font baseline ('p', 'q', etc).

    text_placement.patch.txt

    opened by tytouf 2
Owner
Hugo Barrera
π = 3
Hugo Barrera
Python wrappers for external BART computational imaging tools and internal libraries

bartpy Python bindings for BART. Overview This repo contains code to generate an updated Python wrapper for the Berkeley Advance Reconstruction Toolbo

Max Litster 7 May 9, 2022
An executor that performs standard pre-processing and normalization on images.

An executor that performs standard pre-processing and normalization on images.

Jina AI 6 Jun 30, 2022
📷 Python package and CLI utility to create photo mosaics.

?? Python package and CLI utility to create photo mosaics.

Loic Coyle 7 Oct 29, 2022
Create a QR-code Generator app using only Python.

QR-code_Generator Create a QR-code Generator app using only Python. This apps generated a QR code for a single link. Libraryes used in this app --> py

Soham P Phasalkar 1 Oct 17, 2021
Using P5.js, Processing and Python to create generative art

Experiments in Generative Art Using Python, Processing, and P5.js Quick Links Daily Sketches March 2021. | Gallery | Repo | Done using P5.js Genuary 2

Ram Narasimhan 33 Jul 6, 2022
A python based library to help you create unique generative images based on Rarity for your next NFT Project

Generative-NFT Generate Unique Images based on Rarity A python based library to help you create unique generative images based on Rarity for your next

Kartikay Bhutani 8 Sep 21, 2022
Create a 2D mesh for an airfoil in GMSH using python.

GMSHFoil A simple class to create a 2D mesh for an airfoil in GMSH using python. Requirements pip install airfoils

Charilaos Mylonas 1 May 16, 2022
Create QR Code for link using Python

Quick Response QR is short and named for a quick read from a cell phone. Used to view information from transitory media and put it on your cell phone.

Coding Taggers 1 Jan 9, 2022
A collection of python scripts which help you programatically create PNGs or GIFs

A collection of python scripts which help you programatically create PNGs or GIFs and their Metadata in bulk with custom rarity rates, upload them to OpenSea & list them for sale.

Tom 30 Dec 24, 2022
Polyfoto - Create image mosaics.

Polyfoto Create image mosaics. Showcase "Before and After Science" by Brian Eno "Scott 3" by Scott Walker Installation Clone this repository to your l

Shane Drabing 149 Dec 25, 2022
HtmlWebShot - A python3 package which Can Create Images From url, Html-CSS, Svg and from any readable file and texts with many setup features.

A python3 package which Can Create Images From url, Html-CSS, Svg and from any readable file and texts with many setup features

Danish 24 Dec 14, 2022
Create a static HTML/CSS image gallery from a bunch of images.

gallerize Create a static HTML/CSS image gallery from a bunch of images.

Jochen Kupperschmidt 19 Aug 21, 2022
Tool to create a Phunk image with a custom background

Create Phunk image Tool to create a Phunk image with a custom background Installation Clone the repo git clone https://github.com/albanow/etherscan_sa

Albano Pena Torres 6 Mar 31, 2022
A Blender add-on to create interesting meshes using symmetry

Procedural Symmetries This Blender add-on automates the process of iteratively applying a set of reflection planes to a base mesh. The result will con

null 1 Dec 29, 2021
Short piece of code to create a rainbow gif of gradual contours from two shapefiles

rainbow-elevation-gif Short piece of code to create a rainbow gif of gradual con

Jess Roberts 6 Jan 17, 2022
QR-Generator - An awesome QR Generator to create or customize your QR's

QR Generator An awesome QR Generator to create or customize your QR's! Table of

Tristán 1 Jan 28, 2022
Create a random fluent image based on multiple colors.

FluentGenerator Create a random fluent image based on multiple colors. Navigation Example Install Update Usage In Python console FluentGenerator Fluen

null 1 Feb 2, 2022
Generative Art Synthesizer - a python program that generates python programs that generates generative art

GAS - Generative Art Synthesizer Generative Art Synthesizer - a python program that generates python programs that generates generative art. Examples

Alexey Borsky 43 Dec 3, 2022
Nudity detection with Python

nude.py About Nudity detection with Python. Port of nude.js to Python. Installation from pip: $ pip install --upgrade nudepy from easy_install: $ eas

Hideo Hattori 881 Jan 6, 2023