import time
import serial
import os
import sys
from zebrafy import ZebrafyImage

def download_graphic(image_path):
    if image_path is not None:
            with open(image_path, "rb") as image:
                zpl_string = ZebrafyImage(
                    image.read(),
                    format="Z64",
                    invert=False,
                    dither=True,
                    threshold=128,
                    width=220,
                    height=250,
                    pos_x=510,
                    pos_y=10,
                    rotation=270,
                    string_line_break=80,
                    complete_zpl=True,
                ).to_zpl()
                
            # CANAVIDA STATION 3
            # width=450,
            #         height=450,
            #         pos_x=495,
            #         pos_y=470,

            cleaned_zpl = zpl_string.lstrip("^XA")
            cleaned_zpl = cleaned_zpl.split("^XZ")
            cleaned_zpl=cleaned_zpl[0]
            print(cleaned_zpl)
if len(sys.argv) < 2:
    print("No arguments passed!")
    sys.exit(1)

# The first argument is the script name; subsequent arguments are the ones you pass
arg = sys.argv[1]
download_graphic(arg)
