Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Text to Image script #30

Open
dianaw353 opened this issue Sep 10, 2024 · 0 comments
Open

[FEATURE] Text to Image script #30

dianaw353 opened this issue Sep 10, 2024 · 0 comments
Assignees
Milestone

Comments

@dianaw353
Copy link
Owner

This script will take the selected are, same as when you take a screenshot of an area and retrieve the words from it, and output to terminal [silent] or copy to clipboard [copy] i selected language
tesseract use ocr engine and support many languages, just install
sudo pacman -S tesseract tesseract-data-jpn /tesseract-data-eng

then download this script
and make a hyprland key binds

#image to text
bind = Super, Space, exec, ~/.config/scripts/image_to_text.sh copy eng # Image to text english copy to clipboard
bind = Super, Space, exec, ~/.config/scripts/image_to_text.sh silent eng # Image to text english output to terminal
#!/bin/bash

# Dependencies: grim, slurp, tesseract, wl-clipboard

# Usage:
# ./image_to_text.sh [copy|silent] [language]
# - copy: Copy the extracted text to clipboard
# - silent: Output the extracted text to the terminal
# - language: The language code for Tesseract (e.g., eng for English, spa for Spanish)

# Check if the correct number of arguments is provided
if [ "$#" -ne 2 ]; then
  echo "Usage: $0 [copy|silent] [language]"
  exit 1
fi

# Capture the screen area and save it as a temporary image
grim -g "$(slurp $SLURP_ARGS)" "tmp.png"

# Extract text from the image using Tesseract with the specified language
if [ "$1" == "copy" ]; then
  tesseract -l "$2" "tmp.png" - | wl-copy
elif [ "$1" == "silent" ]; then
  tesseract -l "$2" "tmp.png" -
else
  echo "Invalid argument: $1"
  echo "Usage: $0 [copy|silent] [language]"
  rm "tmp.png"
  exit 1
fi

# Remove the temporary image
rm "tmp.png"
@dianaw353 dianaw353 self-assigned this Sep 10, 2024
@dianaw353 dianaw353 added this to the V1.1.1 milestone Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant