text and image
This commit is contained in:
parent
394d63cc65
commit
25192ad561
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
/venv
|
||||
/cats_and_dogs_filtered
|
||||
log.log
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
[submodule "fonts/xbmc-hebrew-fonts"]
|
||||
path = fonts/xbmc-hebrew-fonts
|
||||
url = https://github.com/kodi-il/xbmc-hebrew-fonts.git
|
BIN
fonts/5x5-Tami.ttf
Normal file
BIN
fonts/5x5-Tami.ttf
Normal file
Binary file not shown.
1
fonts/xbmc-hebrew-fonts
Submodule
1
fonts/xbmc-hebrew-fonts
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 3a21983d5c0496a0f5d37088fefb411e2af9db54
|
BIN
pefectFake.jpg
Normal file
BIN
pefectFake.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
4
readme
4
readme
|
@ -1,6 +1,10 @@
|
|||
```py
|
||||
brother_ql -b pyusb -m QL-550 -p usb://0x04f9:0x2016 print -l 62 pefectFake.jpg --dither
|
||||
```
|
||||
```
|
||||
byobu new-window -n 'printer' 'cd ~/printBash && bash switch.sh'
|
||||
```
|
||||
|
||||
|
||||
To command the camera in the terminal I suggest to use the fswebcam package. To install:
|
||||
|
||||
|
|
12
switch.sh
Executable file
12
switch.sh
Executable file
|
@ -0,0 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Create a new window named 'printer' and set the layout and locale within that window
|
||||
tmux new-window -n 'printer' 'cd ~/printme && python txt.py; bash'
|
||||
|
||||
# Capture the new window ID
|
||||
new_window_id=$(tmux list-windows -F "#{window_id}" | tail -n 1)
|
||||
|
||||
# Loop through all sessions and set the new window as the current window
|
||||
tmux list-sessions -F "#{session_id}" | while read -r session_id; do
|
||||
tmux select-window -t $session_id:$new_window_id
|
||||
done
|
96
txt.py
96
txt.py
|
@ -1,48 +1,93 @@
|
|||
|
||||
import logging
|
||||
import argparse
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
import subprocess
|
||||
import textwrap
|
||||
import threading
|
||||
from queue import Queue
|
||||
import keyboard
|
||||
# Initialize logging
|
||||
logging.basicConfig(filename='your_log_file.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
|
||||
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.")
|
||||
# CLI argument parsing
|
||||
parser = argparse.ArgumentParser(description="Image Generation and Printing")
|
||||
parser.add_argument('--threading', action='store_true', help="Use threading for print queue processing")
|
||||
args = parser.parse_args()
|
||||
|
||||
def camera():
|
||||
print("cam")
|
||||
webcam_command = "fswebcam webcam.jpg ; brother_ql -b pyusb -m QL-550 -p usb://0x04f9:0x2016 print -l 62 --dither webcam.jpg"
|
||||
print_queue.add_to_queue(webcam_command)
|
||||
subprocess.run(webcam_command, shell=True)
|
||||
|
||||
logging.info("Arrow key pressed. Webcam photo command added to queue.")
|
||||
|
||||
|
||||
# A Python function to map ASCII characters to their Hebrew counterparts
|
||||
def map_to_hebrew(input_text):
|
||||
# Mapping of ASCII to Hebrew characters
|
||||
ascii_to_hebrew = {
|
||||
'a': 'א',
|
||||
'b': 'ב',
|
||||
'c': 'ג',
|
||||
'd': 'ד',
|
||||
'e': 'ה',
|
||||
'f': 'ו',
|
||||
'g': 'ז',
|
||||
'h': 'ח',
|
||||
'i': 'ט',
|
||||
'j': 'י',
|
||||
'k': 'כ',
|
||||
'l': 'ל',
|
||||
'm': 'מ',
|
||||
'n': 'נ',
|
||||
'o': 'ס',
|
||||
'p': 'ע',
|
||||
'q': 'פ',
|
||||
'r': 'צ',
|
||||
's': 'ק',
|
||||
't': 'ר',
|
||||
'u': 'ש',
|
||||
'v': 'ת',
|
||||
'w': 'ץ',
|
||||
'x': 'ך',
|
||||
'y': 'ן',
|
||||
'z': 'ם',
|
||||
# Add any other characters you want to map
|
||||
}
|
||||
|
||||
# Convert the input text
|
||||
output_text = ''.join([ascii_to_hebrew.get(char, char) for char in input_text.lower()])
|
||||
|
||||
return output_text
|
||||
|
||||
while True:
|
||||
user_input = input("Type something (or press Enter to generate image): ")
|
||||
print(user_input)
|
||||
logging.info(f"User input: {user_input}")
|
||||
if user_input =="+":
|
||||
camera()
|
||||
elif user_input != "":
|
||||
|
||||
if user_input != "":
|
||||
print("Generating image...")
|
||||
|
||||
mapped_text = map_to_hebrew(user_input)
|
||||
|
||||
logging.info("Generating image...")
|
||||
img_width = 696
|
||||
|
||||
# Wrap text if a word is longer than 8 letters
|
||||
wrapped_text = textwrap.fill(user_input, width=8)
|
||||
wrapped_text = textwrap.fill(mapped_text, 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
|
||||
font_size = img_width // 6
|
||||
ttfont="/home/tasmi/printme/5x5-Tami.ttf"
|
||||
ttfont="/home/tasmi/printme/VarelaRound-Regular.ttf"
|
||||
ttfont="/home/tasmi/printme/fonts/xbmc-hebrew-fonts/Roboto-Bold-xbmc-il.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
|
||||
line_height = font_size + 10
|
||||
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"
|
||||
|
@ -50,4 +95,7 @@ while True:
|
|||
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.")
|
||||
logging.info("Image generated and print command added to queue. Returning to input.")
|
||||
|
||||
# Uncomment this line if you'd like to listen for arrow key events.
|
||||
# keyboard.on_press_key("up", on_arrow_key)
|
||||
|
|
Loading…
Reference in New Issue
Block a user