2 years ago

#32131

test-img

wimsenOG

Python, Code128.png gets blurred

enter image description here

When the stored data get more and I resize the image I lose details and the code can't get scaned.

I want to create a Code128.png with a certain size(30mm*10mm). I'm not able to find a solution to this problem. I'm able to change the Size, but the Image gets unreadable(blurred).

first attempt:

import barcode
from barcode.writer import ImageWriter
from PIL import Image
from reportlab.lib.units import mm
from reportlab.platypus import Image
from pystrich.code128 import Code128Encoder

 EAN = barcode.get_barcode_class('code128')
 ean = EAN('H6.2.9-LED1-D0-USB-SM00', writer=ImageWriter())
 fullname = ean.save(r'C:\Users\Pictures\Code128')
 image = Image.open(r'C:\User\Pictures\Code128.png')
 new_image = image.resize((150, 20))
 new_image.save(r'C:\Users\Pictures\M_Code128.png')

second attempt:

barcode = Code128.Code128("123456789",barHeight=.9*inch,barWidth = 1.2)
barcode.save(r'C:\Users\Pictures\P_Code128.png'

third attempt:

 encoder = Code128Encoder('123456789')
 encoder.save(r'C:\Users\Pictures\Code128.png')
 img = Image(r'C:\Users\Pictures\Code128.png', width= 10*mm, 
 height=20*mm)
 img.save(r'C:\Users\Pictures\T_Code128.png')

python

size

barcode

code128

0 Answers

Your Answer

Accepted video resources