Code Monkey home page Code Monkey logo

textshot's Introduction

TextShot

GitHub stars GitHub forks GitHub license Code style: black

Take a screenshot and copy its text content to the clipboard. Works on Windows, macOS, and most modern Linux distros.

TextShot Demo

Use

textshot -h prints the available command line options:

usage: textshot [-h] [-i INTERVAL] [langs]

Take a screenshot and copy its text content to the clipboard.

positional arguments:
langs                 languages passed to tesseract, eg. "eng+fra" (default: eng)

optional arguments:
-h, --help            show this help message and exit
-i INTERVAL, --interval INTERVAL
                        select a screen region then take textshots every INTERVAL milliseconds

Examples

  • Basic usage: textshot opens an overlay where a rectangle can be drawn around the text to be copied.

  • Alternate languages: textshot eng+fra specifies use of English as the primary language and French as the secondary language. Make sure that the appropriate data files for Tesseract are installed for other languages. A list of all supported languages can be found here.

  • Continuously copy text content: textshot --interval 200 draw a rectangle at a screen region then copy text from it every 200ms.

Hotkeys

It is recommended to attach a global hotkey to this tool, so you can run it without opening a console and typing in the command.

On Windows, one can accomplish this by using an AutoHotkey script; textshot.ahk contains a sample AHK script that can be used.

On Ubuntu, open the Keyboard Settings, which shows you all the Gnome shortcuts. At the bottom there is a + button to add your own shortcuts. Click it and set the command to textshot. In case you are using a virtual environment, the textshot path above should point to the environment's textshot.

The process on other operating systems can be found by searching how to run a shell command with a keyboard shortcut.

Installation

Prerequisites

  • Install Google's Tesseract OCR Engine, and ensure that tesseract can be reached from the command line by adding the directory to your system path.

Installation with pip

$ pip install textshot
$ textshot

You may wish to use a virtual environment if the dependencies conflict with others on your machine.

Installation from source

  • Clone this repository... git clone https://github.com/ianzhao05/textshot.git
  • ...and cd into it: cd textshot
  • Run pip install . (for development, you may install with pip install -e . which will allow you to test your modifications without reinstall)
  • You may now run textshot

From repository

@rigred has added this to the AUR, so Arch Linux users can install the package textshot-git with their AUR helper. For example, yay -S textshot-git. This may not be up to date, so if you encounter issues, use the normal installation method above.

Troubleshooting

macOS

You may need to give permission to capture the screen. You can do so by going to System Preferences > Security & Privacy > Privacy > Screen Recording, then checking the box for Terminal/iTerm.

Linux

If the text shows up correctly in the notification, but you cannot paste it, install xclip (e.g. with sudo apt install xclip).

textshot's People

Contributors

0xflotus avatar 1ace avatar alinuxperson avatar br3w0r avatar dependabot[bot] avatar ianzhao05 avatar jonahsol avatar krithikvaidya avatar ravipabari avatar snoopydevelops avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

textshot's Issues

Consider adding pyproject.toml for package installation

Here is a pyproject.toml example

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "textshot"
version = "0.0.1"
authors = [
  { name="Ian ianzhao05", email="[email protected]" },
]
description = "Python tool for grabbing text via screenshot"
readme = "README.md"
requires-python = ">=3.7"
classifiers = [
    "Programming Language :: Python :: 3",
    "License :: OSI Approved :: MIT License",
    "Operating System :: OS Independent",
]
dynamic = ["dependencies"]

[project.urls]
"Homepage" = "https://github.com/ianzhao05/textshot"
"Bug Tracker" = "https://github.com/ianzhao05/textshot/issues/"

[project.scripts]
textshot = "textshot.textshot:main"

[tool.setuptools.dynamic]
dependencies = {file = ["requirements.txt"]}

[tool.setuptools.packages.find]
where = ["textshot"]

It may need some tweaking and modifying the project to relocate python files in textshot and changing the way import is done by using something like from .ocr import … for example.

It would be helpful to make a working package for linux distributions.

You then build and install the package with:

python3 -m build --wheel
python -m installer dist/*.whl

Segmentation fault, (core dumped)

I tried to run textshot on my fedora Linux machine and I got a segmentation fault error:
Traceback (most recent call last): File "/home/maerqin/PycharmProjects/Screenshot_To_Text/venv/lib/python3.12/site-packages/textshot/textshot.py", line 11, in <module> from .logger import log_copied, log_ocr_failure ImportError: attempted relative import with no known parent package [1] 82030 segmentation fault (core dumped) python textshot.py -h

License

Please add a license file.

[Feature suggestion] Add an auto magnification

Sometimes the target is too small on the screen and I can't capture it accurately. Maybe it is a good idea to add a magnified image based on what is around the cursor when users are capturing the screen.

Selection not from upper left corner

When I make a selection starting not from the upper left corner, but from any other corner, instead of the text in selection it returns some long random text, which seems to be the text from all screen.

To reproduce, make a selection of some text from, for example, lower right corner to upper left corner.

2022-02-09.11.12.21.mp4

Error

ERROR: An error occurred when trying to process the image: (1, "Tesseract Open Source OCR Engine v3.05.00dev with Leptonica read_params_file: Can't open txt Warning in pixReadMemPng: work-around: writing to a temp file libpng warning: Application built with libpng-1.4.3 but running with 1.5.14 Error in pixReadStreamPng: png_ptr not made Error in pixReadMemPng: pix not read Error in pixReadMem: png: no pix returned Error during processing.")

ERROR: Unable to read text from image, did not copy

On recent Arch linux with i3wm window manager I often get ERROR: Unable to read text from image, did not copy.

I have :

  • python-pyqt5 : 5.15.8
  • python-pyqt5-sip: 12.11.1
  • python-pillow: 9.4.0
  • python-pytesseract: 0.3.10

Doesn't support MacBook Fullscreen

This tool could only take a shot on its current desktop. However, MacBook has a multi-desktop feature, and you can't ask this tool to take a shot on the desktop where the terminal is opened. Hope the author can support multi-desktop screenshots.

Size limitation for text, and sometimes prior OCR conversion in clipboard is not replaced with new OCR conversion

Hi
I think this is a really cool idea to make OCR simple to do and allows for correcting OCR mistakes very easily.
I am on a Windows machine and I find that I need to OCR a large text image in parts because it doesn't handle
a lot of text well. Is there a recommended maximum amount of text that should be selected for conversion?
But even doing OCR in parts, some areas appear to be captured and the "spinning wheel" indicates that
a conversion is being done. But when pasting the text that is in the clipboard to notepad++, it is the text from a prior conversion.
If there is an error in the conversion process, I can't find where it is displayed. Can you please give me some pointers
on getting around these issues?
Thanks!

Doesn't work in multi-monitor setup

I have two screens (let's name them Main and Side). When I open type textshot in a terminal in Side, the Main monitor starts mirroring Side monitor's content.

So, to copy text from Main, I have to open the terminal in Main. This is not a good experience

Does not pause desktop while snipping

The screen overlay does not pause the desktop while snipping. For example, videos and GIFs continue to play in the background. This is inconsistent with Windows's screenshot tools, Snipping Tool and the newer Snip & Sketch.

Raised by @rigred in #12

Added your package to arch linux aur

Just a friendly heads up that I've added your package to the archlinux aur and it will keep itself updated based on the latest git commits to the github repo.
https://aur.archlinux.org/packages/textshot-git

So for arch users it's as easy as installing textshot-git with their favourite aur helper.
yay -S textshot-git

Also is there a way to make textshot pause the desktop (animations like the gif on this page)?
Currently it keeps on animating while in box select mode.

Thanks for the great tool!

macOS Big Sur opens new screen

I just downloaded text shot on my Mac and installed all the dependencies but have been experiencing this weird behavior where as soon as I run it it will open a new screen to the right with no open apps and would only allow me to screenshot there. Did anyone else encounter this or have a fix?

2021-02-27 19:08:54.739 Python[952:13732] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to /var/folders/ld/wjmpqdpj1pq2j4j_svh1j8740000gn/T/org.python.python.savedState

Screen Recording

Failed when have multiple monitors

image

Once I unplugged from external monitors it worked well. The problem is raised from line 29 in textshot.py,
self.screen = QtWidgets.QApplication.screenAt(QtGui.QCursor.pos()).grabWindow(0)

My system is MacOS 10.15.3, with python 3.6.9. Thank you.

textshot on macOS Big Sur

Hi,

On macOS 11.1, invoking python textshot.py throws a Qt GUI error:

QPixmap::fromImage: QPixmap cannot be created without a QGuiApplication
QPixmap: Must construct a QGuiApplication before a QPixmap

Any suggestions? This worked fine before updating to Big Sur. Thank you!

EDIT: This has been tried with a virtual environment.

screenshot "E:\>cd github" output -->"INFO: Copied "AR" to the clipboard"

screenshot "E:>cd github" output -->"INFO: Copied "AR" to the clipboard"

the command line test info:

E:\github>cd..

E:>cd github

E:\github>cd textshot

E:\github\textshot>python textshot.py
**INFO: Copied "E:\github>cd. .
AR

E:\github>cd textshot" to the clipboard**

E:\github\textshot>python textshot.py chi_sim
**INFO: Copied "ET
E:N>cd github

E:Ngithub>cd textshot" to the clipboard**

E:\github\textshot>

Tesseract Process Timeout

Appears to not work on more than 5 words at a time, presents with error

"TextShot"
"An error occurred when trying to process the image: Tesseract process timeout"

could not work on MacOS

on Mac get

INFO: Unable to read text from image, did not copy

seems pyperclip do not work properly on MacOS.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.