Skip to content

Instantly share code, notes, and snippets.

@itpcc
Created January 14, 2023 05:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itpcc/a7164eb165bd06f95a665e12da74a273 to your computer and use it in GitHub Desktop.
Save itpcc/a7164eb165bd06f95a665e12da74a273 to your computer and use it in GitHub Desktop.
Greenshot: Decode QR code from the screenshot

How?

  1. Install Python 3 (I use 3.10)
  2. Run the following command (to install dependencies)
python3 -m pip install --upgrade pyzbar Pillow pyperclip
  1. Copy main.py to C:\qrcode-decode (Or whereever, just being able to run from command line)
  2. On Greenshot's icon located in the taskbar, right click and click "Configure external commands" image
  3. On "External command settings" window, click "New" button.

image

  1. On "Configure command" window, fill up the following values:
  • Name: Decode QR
  • Command: C:\Python310\python.exe (Or anywhere that Python executable file locaated)
  • Argument: C:\qrcode-decode\main.py "{0}"

then click "Ok"

When you take a screenshot and choose "Decode QR", if the script can detect QR code, it'll copy the value (URL, number, text, etc.) from the first QR code to your clipboard.

#!/usr/bin/env python
"""main.py: Decode QR code and copy its result to user's clipboard. Derived from https://stackoverflow.com/a/49609996 and https://stackoverflow.com/a/11063483"""
__author__ = "ITPCC <dev@rachasak.org>"
__copyright__ = "MIT"
import sys
from pyzbar.pyzbar import decode
from PIL import Image
import pyperclip
decRes = decode(Image.open(sys.argv[1]))
if decRes:
pyperclip.copy(decRes[0].data.decode("utf-8"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment