Edit: after the answer, I noticed that you have a factory that sets quiet_zone to 1.0 . Change it to 6.5 and I assume that it will look normal.
Edit2: I misunderstood the exact problem you are facing.
For some reason, the author of pyBarcode places the text in the center of the barcode. When the render method calls _paint_text() , it goes into xpos/2 , which sets it in the middle of the barcode. I assume this is normal with the default font used, but when you enlarge the font, it no longer fits.
Instead, I was able to put it on the left side by overriding the _paint_text() method. In the last line below, the pos variable is just a tuple containing the coordinate (x, y) that tells PIL where to draw the text on the barcode. So I made sure that x is built using a barcode. If you need it to be right-aligned, you can play with the xpos variable to get it where you need it.
Take a picture:
class MyImageWriter(ImageWriter): def calculate_size(self, modules_per_line, number_of_lines, dpi=300): width = 2 * self.quiet_zone + modules_per_line * self.module_width height = 1.0 + self.module_height * number_of_lines if self.text: height += (self.font_size + self.text_distance) / 3 return int(mm2px(width, dpi)), int(mm2px(height, dpi)) def _paint_text(self, xpos, ypos):
source share