Add initial project structure and core functionality for label extraction and PDF generation
- 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.
This commit is contained in:
36
read_image.py
Normal file
36
read_image.py
Normal file
@@ -0,0 +1,36 @@
|
||||
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("Код не распознан")
|
||||
Reference in New Issue
Block a user