Comments (6)
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)`
from python-barcode.
For anyone reading this today, _paint_text
has been renamed to _create_text
.
from python-barcode.
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
from python-barcode.
Would you like to make that into a PR?
from python-barcode.
Was this ever integrated into main? I don't see it in https://github.com/WhyNotHugo/python-barcode/blob/main/barcode/writer.py
from python-barcode.
For anyone reading this today,
_paint_text
has been renamed to_create_text
.
Just to clarify, the rename is only on SVGWriter, in ImageWriter still uses the _paint_text
from python-barcode.
Related Issues (20)
- How to use with Pillow image
- ISBN-13 starting with 979 HOT 1
- Text placement in ImageWriter HOT 2
- UPC/UPCA final output doesn't include guard bars HOT 1
- Add some form of tests reading the barcodes
- no support for MSI (Plessey) barcodes HOT 2
- EAN13 calculate_checksum() generates inconsistent values HOT 6
- better formating for GS1_128 HOT 1
- Unable to generate PNG using pillow 10 HOT 3
- dpi HOT 1
- generating barcode error HOT 1
- Unexpected ">" symbol at the end of generated EAN-13 barcode HOT 2
- module_width not working HOT 1
- invalid ppem value with 0.15.1 but not with 0.14.0 HOT 5
- Incompatibility with pillow 10.0.1 HOT 10
- Error on the number generated HOT 11
- Redable text under bars is cut out from the image HOT 2
- Support for Code128 FNC4 / ISO-8859-1
- Why does `Barcode.build()` always return a singleton list? HOT 2
- GS1-128 images are cut-off HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-barcode.