Shot2Text

How to Copy Code From a Screenshot (Clean & Private)

Crop out line numbers, keep sharp pixel edges, check the six classic character swaps, and keep private code off cloud servers.

Copying prose from a screenshot is forgiving — a missing comma still reads fine. Copying code from a screenshot is brutal: one 0 read as O, one curly quote, or one dropped underscore breaks the whole script.

Here is the fastest workflow for turning a code screenshot, stack trace, or terminal window into runnable text — and the exact six characters you should always check before running it.

Why copying code locally matters more than usual

Developer screenshots leak secrets without looking like secrets. A terminal window shows internal hostnames, AWS account IDs, .env paths, customer IDs in a stack trace, or proprietary source code from a private repository.

Uploading that screenshot to a random cloud OCR website puts internal code on someone else's server. Shot2Text runs Tesseract directly inside your browser tab — the image never leaves your machine, which you can verify in your browser's Network panel.

The clean workflow for code screenshots

  1. Crop out the gutter and line numbers. Leaving line numbers (14, 15, 16) inside your screenshot forces the reader to merge them into the start of every line of code. Drag your screenshot box strictly around the code itself.
  2. Zoom in before capturing. If the code is in a browser, documentation page, or YouTube tutorial, zoom to 150% or go full-screen first. Monospace punctuation (., ,, ;, :, ', `) vanishes below 12–14 pixels tall.
  3. Avoid low-contrast dark themes when you have a choice. Dark editors with pastel syntax colors (muted red or blue on charcoal) convert poorly to greyscale. If you control the screen, switch to a light theme for five seconds before screenshotting. If you cannot (for example, a colleague's screenshot or a video), crop tightly so bright window borders do not skew contrast.
  4. Paste straight from the clipboard (Ctrl + V / ⌘ + V) into Shot2Text instead of exporting a compressed JPG. PNG or raw clipboard captures keep sharp pixel edges on thin characters like | and /.
  5. Run a formatter after pasting. Plain OCR does not reliably preserve 2-space vs 4-space indentation. Paste the extracted text into VS Code (or your editor) and run Prettier, Black, gofmt, or rustfmt — it fixes indentation instantly and flags any syntax typo immediately.

The six character pairs OCR gets wrong in code

Even on a sharp screenshot, scan your pasted code for these six classic OCR swaps before running a command:

What was in the image What OCR often outputs Where it bites hardest
0 (zero) vs O (capital O) Swapped either way Hex codes, port numbers, hashes, CLI flags
1 (one) vs l (lowercase L) vs I (capital I) Merged into l or 1 Variable names, URLs, Base64 tokens
_ (underscore) Dropped or read as - or space Python snake_case, env vars
' / " / ` Curly quotes or missing backticks Shell commands, JS template literals
{ / } / ( / ) Misread as [ or 1 JSON objects, arrow functions
== / === / != Collapsed to = or l= Conditionals (valid syntax, wrong logic!)

Never paste OCR'd shell commands straight into a production terminal. Paste into a scratch editor first, glance over flags like -rf, paths, and hostnames, then run it.

Honest limits: when not to use plain OCR for code

  • Two-column diffs (GitHub split view): Plain OCR reads line by line across the entire width of the image, which interleaves the left and right columns into gibberish. Crop one side of the diff at a time.
  • Tiny screenshots sent over Slack or WhatsApp: Chat apps recompress PNGs into fuzzy JPEGs. Ask for the raw code block or the original PNG if punctuation looks smeared — see best image format for OCR for why compression destroys thin characters.
  • Python indentation inside huge screenshots: Because Python uses whitespace for structure, paste smaller 15–25 line blocks rather than a full 80-line screen, so fixing indentation takes seconds.

For general troubleshooting on blurry captures, check why OCR comes out messy and six ways to fix it or how to copy text from a YouTube video.

Quick answers

Does screenshot-to-text preserve code indentation?
No. Plain OCR reads characters accurately on sharp captures but does not reliably reconstruct 2-space or 4-space indentation. Paste the extracted text into your editor and run an auto-formatter (Prettier, Black, gofmt) to restore clean indentation and highlight syntax typos.
Should I include editor line numbers in a code screenshot?
Always crop out line numbers before running OCR. Otherwise, the reader treats line numbers as the first token of every line of code, forcing you to delete them manually line by line.
Is it safe to paste proprietary code or stack traces into Shot2Text?
Yes. Shot2Text runs recognition completely inside your browser tab using local language data — your code screenshot or stack trace is never uploaded to any server.

Try it on your screenshot right now

Open the reader, press Ctrl+V (or Cmd+V on Mac), and copy the words in seconds. Everything runs inside your browser tab — nothing is uploaded and no sign-up is required.

Extract Code From a Screenshot All OCR guides →

How to Extract Text From a Video (Slides, Code & Audio) How to extract text from a video (on-screen slides, code, subtitles vs spoken audio). Fast 5-second clipboard OCR workflow with zero file uploads. Local Browser OCR vs Cloud OCR — Privacy & Accuracy Compared Local browser OCR vs cloud OCR compared honestly: privacy, accuracy on screenshots vs handwriting and tables, speed, and how to verify zero uploads. How to Copy Code From a Screenshot (Clean & Private) How to copy code or error logs from a screenshot cleanly without uploading private code. Cropping tips, dark-mode fixes, and the 6 OCR typos to check. How to Copy Text From a YouTube Video (Code, Slides & Links) How to copy text, code, or slides from a paused YouTube video in seconds without an extension. Exact quality settings, frame tricks, and local browser OCR. How to Copy Text From a Zoom or Teams Screen Share How to copy text from a Zoom, Microsoft Teams, or Google Meet screen share quickly and privately using clipboard paste and local browser OCR. Extract a Table From a Screenshot — What Actually Works OCR gives you text, not cells. The crop-per-column trick, the spreadsheet splitting step, and the digit confusions that wreck a column of numbers. How to Screenshot on a Mac and Get the Text Out of It Every Mac capture shortcut, which one to use for text, and how to pull the words out with Preview. Plus why a Mac screenshot is such good input for OCR. Best Image Format for OCR — PNG vs JPG vs WebP Compared Why PNG usually reads best, why JPG is the usual culprit when text comes out wrong, and the resolution numbers that matter more than the format choice. Why OCR Comes Out Messy — Six Causes and How to Fix Them Six causes behind a bad text-recognition result, how to diagnose which one you have from the output itself, and the order to try fixes in. Convert Multiple Screenshots to Text — Honest Guide There is no batch mode here, and this page explains why plus the fastest order to work through a pile. Includes when a desktop batch tool is the right answer. Convert an Image to Text in Excel — Into Real Columns Get numbers from a picture into spreadsheet cells: extract the text, then use Text to Columns. Plus the leading-zero trap that catches everyone. Convert an Image to Text in Word — Windows & Mac Routes Word has no import-image-as-text command, but OneNote does, and Preview does on Mac. What formatting survives, and what you will rebuild. How to Extract Text From an Image (Every Method, Ranked) Four ways to get text out of a picture — paste, file, paper, PDF — with the failure modes for each. When the result comes out wrong, this is why. How to Extract Text From an Image on Android (4 Routes) Android has text recognition in three places, plus a browser route that works on every phone. Google Lens, Pixel recents, Samsung keyboard, and more. How to Extract Text From an Image on iPhone (Live Text) iPhone has text recognition built in since iOS 15. Where Live Text lives, what it does well, and the cases where it needs something else. How to Extract Text From a Screenshot (4 Methods) A screenshot is the cleanest input for text extraction. Four ways to turn one into text, including the Windows and macOS built-ins most people miss.