- Created .gitignore to exclude unnecessary files and directories. - Implemented build_pdf.py for generating PDF labels from Excel data, including barcode rendering. - Added read_image.py for extracting DataMatrix codes from images using zxing-cpp. - Introduced render_eps.py for converting EPS images to PNG format with Ghostscript. - Updated README.md with project overview, features, installation instructions, and usage guidelines. - Included requirements.txt for dependency management. - Added resources for logos and sample Excel template. - Compressed Ghostscript binaries into Ghostscript.zip for easy integration.
36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
import zxingcpp as zxing_cpp
|
||
from PIL import Image
|
||
import base64
|
||
|
||
def read_datamatrix_zxing(file_path: str) -> str:
|
||
# Открываем изображение через Pillow
|
||
img = Image.open(file_path)
|
||
|
||
# Читаем штрих-код.
|
||
# zxing_cpp.read_barcodes умеет работать напрямую с объектами PIL
|
||
results = zxing_cpp.read_barcodes(img)
|
||
|
||
if not results:
|
||
print("Коды не найдены на изображении.")
|
||
return ''
|
||
|
||
# Берем первый найденный код
|
||
result = results[0]
|
||
|
||
# Извлекаем именно байты (важно для непечатаемых символов GS/FNC1)
|
||
raw_bytes = result.bytes
|
||
|
||
# Кодируем байты в Base64
|
||
# b64encode возвращает bytes, поэтому делаем .decode('ascii') для получения строки
|
||
b64_string = base64.b64encode(raw_bytes).decode('ascii')
|
||
|
||
return b64_string
|
||
|
||
if __name__ == "__main__":
|
||
image_path = "data/output.png"
|
||
data = read_datamatrix_zxing(image_path)
|
||
|
||
if data:
|
||
print(f"Успешно прочитано: {data}")
|
||
else:
|
||
print("Код не распознан") |