On 10/3/24 11:21, Max Nikulin wrote:
Is the QR image a raster one? I am unsure concerning its printer dots
per QR pixel ratio. Let's take e.g. 4 as a value inconvenient for
direct scaling from 300dpi to 203dpi. I expect that upscaling it by 3
and downscaling the result by 4 with disabled smoothing (e.g. using
splines) should generate an image that is 1.5% larger than the one
suitable for 203dpi. So setting 98.5% scaling for printer should allow
to achieve sharp QR image without re-encoding QR.
In my case I have never seen a bigger dogs breakfast of a pdf! It has
many elements in different formats including bitmaps, scalable vector
graphics, and text elements. That and some images are colour and some
black and white. I just preprocess it
I have far less problems with the QR code (in my case data_matrix code)
than with the barcode. The pixel elements of the QR code are much larger
than the lines in a barcode so there is much less chance for pixel
ambiguity.
I think i you make it 'big enough' it will scan fine. So a factor of 2
magnification should work with a QR code.
I spent many (un)happy hours with gimp and imagemagick to try and get
the best solution for barcodes. Sadly there is none other than print the
barcode as big as possible in your page real-estate.
I spent an hour today with my friend GPT4 and python and I can now pluck
out any and all codes from my mailing labels and I next plan to generate
new labels at 203dpi using freshly encoded barcodes and data_matrix codes.
Here is some experimental code
from PIL import Image
import pyzbar.pyzbar as pyzbar
import qrcode # For generating QR codes
from barcode import EAN13, generate # Using EAN13 as an example; this
might vary
from barcode.writer import ImageWriter
import os
from pdf2image import convert_from_path
def pdf_to_image(pdf_path, dpi=600):
images = convert_from_path(pdf_path, dpi=dpi)
for img in images:
yield img
def detect_and_extract_codes(images):
for img in images:
detected_codes = pyzbar.decode(img)
for code in detected_codes:
print(code)
if code.type == 'QRCODE':
# Process QR code
process_qr_code(code)
else:
# Process other types of barcodes
process_barcode(code)
def process_qr_code(code):
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(code.data.decode())
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
img.show() # Or save the image