commit 394d63cc65f723f9e8aa4691ba33c4f2abbab263 Author: Yair Date: Wed Sep 20 02:25:27 2023 +0100 works diff --git a/readme b/readme new file mode 100644 index 0000000..b58f4e2 --- /dev/null +++ b/readme @@ -0,0 +1,25 @@ +```py +brother_ql -b pyusb -m QL-550 -p usb://0x04f9:0x2016 print -l 62 pefectFake.jpg --dither +``` + +To command the camera in the terminal I suggest to use the fswebcam package. To install: + +`sudo apt install fswebcam` + +To take an image with a certain resolution and hide the standard banner: + +`fswebcam -r 1280x720 --no-banner /images/image1.jpg` + +To find the supported webcam resolutions: + +`v4l2-ctl --list-formats-ext` + +You could also use ffmpeg to take images and video. To install: + +`sudo apt install ffmpeg` + +To take an image: + +`ffmpeg -f v4l2 -video_size 1280x720 -i /dev/video0 -frames 1 out.jpg` + +A more advanced alternative is mjpeg-streamer, which enables you to stream the camera in a browser. You can find a detailed tutorial how to set that up here. \ No newline at end of file diff --git a/txt.py b/txt.py new file mode 100644 index 0000000..4150a32 --- /dev/null +++ b/txt.py @@ -0,0 +1,53 @@ + +from PIL import Image, ImageDraw, ImageFont +import subprocess +import textwrap +import keyboard + +def on_arrow_key(e): + subprocess.run("fswebcam webcam.jpg ; brother_ql -b pyusb -m QL-550 -p usb://0x04f9:0x2016 print -l 62 --dither webcam.jpg", shell=True) + print("Arrow key pressed. Webcam photo taken and printed.") + +while True: + user_input = input("Type something (or press Enter to generate image): ") + print(user_input) + + if user_input != "": + print("Generating image...") + + img_width = 696 + + # Wrap text if a word is longer than 8 letters + wrapped_text = textwrap.fill(user_input, width=8) + num_lines = wrapped_text.count('\n') + 1 + + # Calculate font size to fit the width of the image + font_size = img_width // 6 # Adjust as needed + ttfont="/home/tasmi/printme/5x5-Tami.ttf" + ttfont="/home/tasmi/printme/VarelaRound-Regular.ttf" + font = ImageFont.truetype(ttfont, font_size) + + # Calculate image height based on the number of lines and font size + line_height = font_size + 10 # Include some padding, adjust as needed + img_height = num_lines * line_height + 200 + + image = Image.new('RGB', (img_width, img_height), 'white') + d = ImageDraw.Draw(image) + + # Calculate position to center-align the text + text_width, text_height = d.textsize(wrapped_text, font=font) + x = (img_width - text_width) // 2 + y = (img_height - text_height) // 2 + + print(wrapped_text) + + d.text((x, y), wrapped_text, font=font, fill=(0, 0, 0)) + + image.save("output.png") + + printer_ql550="0x2016" + printer_id1="000M6Z401370" + command = f"brother_ql -b pyusb --model QL-550 -p usb://0x04f9:{printer_ql550}/{printer_id1} print -l 62 output.png" + subprocess.run(command, shell=True) + + print("Image generated. Returning to input.")