Skip to content

Setting font_size to 0 (to remove text as documented) raises ValueError #245

@aradkdj

Description

@aradkdj
/home/aradkdj/.local/share/virtualenvs/FastAPIProject-SQp2g_y9/bin/python /var/lib/snapd/snap/pycharm-professional/484/plugins/python-ce/helpers/pydev/pydevconsole.py --mode=client --host=127.0.0.1 --port=36785 
import sys; print('Python %s on %s' % (sys.version, sys.platform))
sys.path.extend(['/home/aradkdj/Documents/learning/FastAPIProject'])
PyDev console: starting.
Python 3.10.17 (main, May 20 2025, 00:33:58) [GCC 15.1.1 20250425 (Red Hat 15.1.1-1)] on linux
>>> from io import BytesIO
>>> from barcode import Code128
>>> from barcode.writer import ImageWriter
>>> rv = BytesIO()
>>> image = Code128("i love python-barcode", ImageWriter())
>>> image.write(
...     rv,
...     options={
...         "font_size": 0,
...     },
... )
Traceback (most recent call last):
  File "/var/lib/snapd/snap/pycharm-professional/484/plugins/python-ce/helpers/pydev/pydevconsole.py", line 364, in runcode
    coro = func()
  File "<input>", line 2, in <module>
  File "/home/aradkdj/.local/share/virtualenvs/FastAPIProject-SQp2g_y9/lib/python3.10/site-packages/barcode/base.py", line 80, in write
    output = self.render(options, text)
  File "/home/aradkdj/.local/share/virtualenvs/FastAPIProject-SQp2g_y9/lib/python3.10/site-packages/barcode/codex.py", line 255, in render
    return super().render(options, text)
  File "/home/aradkdj/.local/share/virtualenvs/FastAPIProject-SQp2g_y9/lib/python3.10/site-packages/barcode/base.py", line 100, in render
    return self.writer.render(code)
  File "/home/aradkdj/.local/share/virtualenvs/FastAPIProject-SQp2g_y9/lib/python3.10/site-packages/barcode/writer.py", line 269, in render
    self._callbacks["paint_text"](xpos, ypos)
  File "/home/aradkdj/.local/share/virtualenvs/FastAPIProject-SQp2g_y9/lib/python3.10/site-packages/barcode/writer.py", line 440, in _paint_text
    font = ImageFont.truetype(self.font_path, font_size)
  File "/home/aradkdj/.local/share/virtualenvs/FastAPIProject-SQp2g_y9/lib/python3.10/site-packages/PIL/ImageFont.py", line 880, in truetype
    return freetype(font)
  File "/home/aradkdj/.local/share/virtualenvs/FastAPIProject-SQp2g_y9/lib/python3.10/site-packages/PIL/ImageFont.py", line 877, in freetype
    return FreeTypeFont(font, size, index, encoding, layout_engine)
  File "/home/aradkdj/.local/share/virtualenvs/FastAPIProject-SQp2g_y9/lib/python3.10/site-packages/PIL/ImageFont.py", line 232, in __init__
    raise ValueError(msg)
ValueError: font size must be greater than 0, not 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions