1
0
Fork
You've already forked python-barcode
0

Create barcode without plain text #24

Open
opened 2019年02月19日 10:11:18 +01:00 by AxelRHD · 5 comments
AxelRHD commented 2019年02月19日 10:11:18 +01:00 (Migrated from github.com)
Copy link

Is there an option to generate the barcode without the plain text?

Is there an option to generate the barcode without the plain text?
WhyNotHugo commented 2019年02月20日 19:44:56 +01:00 (Migrated from github.com)
Copy link

You can subclass writers and override the text render method. It probably makes sense to add a flag for this though, since it's a rather common request.

class ImageWitoutTextWriter(ImageWriter):
 def _paint_text(self, xpos, ypos):
 pass
You can subclass writers and override the text render method. It probably makes sense to add a flag for this though, since it's a rather common request. ```python class ImageWitoutTextWriter(ImageWriter): def _paint_text(self, xpos, ypos): pass ```
formgi commented 2019年04月08日 10:44:20 +02:00 (Migrated from github.com)
Copy link

I'm added in class ImageWriter variable print_text. Default value is True, if need create barcode without text, writer=ImageWriter(False)

`class ImageWriter(BaseWriter):

 def __init__(self, print_text=True):
 BaseWriter.__init__(self, self._init, self._paint_module,
 self._paint_text, self._finish)
 self.format = 'PNG'
 self.dpi = 300
 self._image = None
 self._draw = None
 self.print_text = print_text 
 def _init(self, code):
 size = self.calculate_size(len(code[0]), len(code), self.dpi)
 if not self.print_text:
 size = (size[0], int(size[1] * 0.7))
 self._image = Image.new('RGB', size, self.background)
 self._draw = ImageDraw.Draw(self._image)
 def _paint_module(self, xpos, ypos, width, color):
 size = [(mm2px(xpos, self.dpi), mm2px(ypos, self.dpi)),
 (mm2px(xpos + width, self.dpi),
 mm2px(ypos + self.module_height, self.dpi))]
 self._draw.rectangle(size, outline=color, fill=color)
 def _paint_text(self, xpos, ypos):
 if self.print_text:
 font = ImageFont.truetype(FONT, self.font_size * 2)
 width, height = font.getsize(self.text)
 pos = (mm2px(xpos, self.dpi) - width // 2,
 mm2px(ypos, self.dpi) - height // 4)
 self._draw.text(pos, self.text, font=font, fill=self.foreground)`
I'm added in class ImageWriter variable print_text. Default value is True, if need create barcode without text, writer=ImageWriter(False) `class ImageWriter(BaseWriter): def __init__(self, print_text=True): BaseWriter.__init__(self, self._init, self._paint_module, self._paint_text, self._finish) self.format = 'PNG' self.dpi = 300 self._image = None self._draw = None self.print_text = print_text def _init(self, code): size = self.calculate_size(len(code[0]), len(code), self.dpi) if not self.print_text: size = (size[0], int(size[1] * 0.7)) self._image = Image.new('RGB', size, self.background) self._draw = ImageDraw.Draw(self._image) def _paint_module(self, xpos, ypos, width, color): size = [(mm2px(xpos, self.dpi), mm2px(ypos, self.dpi)), (mm2px(xpos + width, self.dpi), mm2px(ypos + self.module_height, self.dpi))] self._draw.rectangle(size, outline=color, fill=color) def _paint_text(self, xpos, ypos): if self.print_text: font = ImageFont.truetype(FONT, self.font_size * 2) width, height = font.getsize(self.text) pos = (mm2px(xpos, self.dpi) - width // 2, mm2px(ypos, self.dpi) - height // 4) self._draw.text(pos, self.text, font=font, fill=self.foreground)`
WhyNotHugo commented 2020年08月10日 20:32:33 +02:00 (Migrated from github.com)
Copy link

Would you like to make that into a PR?

Would you like to make that into a PR?
georgek commented 2021年02月05日 15:50:22 +01:00 (Migrated from github.com)
Copy link

For anyone reading this today, _paint_text has been renamed to _create_text.

For anyone reading this today, `_paint_text` has been renamed to `_create_text`.
nabelekt commented 2021年03月18日 06:14:51 +01:00 (Migrated from github.com)
Copy link

Was this ever integrated into main? I don't see it in https://github.com/WhyNotHugo/python-barcode/blob/main/barcode/writer.py

Was this ever integrated into main? I don't see it in https://github.com/WhyNotHugo/python-barcode/blob/main/barcode/writer.py
Sign in to join this conversation.
No Branch/Tag specified
main
pre-commit-ci-update-config
extensibility
fix_sizes
feature/longer_guard_bar
ean-without-checksum
readme-formatting
cleaning
cleanup
srolin/master
michieldwitte/left-alignment-fix
v0.13.1
v0.13.0
v0.12.0
v0.11.0
v0.10.0
v0.9.0
v0.8.3
v0.8.2
v0.8.1
v0.8.0
0.8beta1
0.7
0.7beta4
0.7beta3
0.7beta2
v0.6
v0.6b3
v0.6b2
v0.6b1
v0.5.0
v0.5.0b1
v0.4.3
v0.4.2
v0.4.1
v0.4
v0.4b2
v0.4b1
v0.3
v0.3b1
v0.2.1
v0.1
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
WhyNotHugo/python-barcode#24
Reference in a new issue
WhyNotHugo/python-barcode
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?