From 15e827fbaa61e2aba72d6e4aa5b6f1f761e3e77d Mon Sep 17 00:00:00 2001 From: Urban Date: Fri, 17 Jul 2026 17:56:23 +0200 Subject: [PATCH] added comment --- scripts/ocr.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/scripts/ocr.sh b/scripts/ocr.sh index e6109c7..39d4d5c 100755 --- a/scripts/ocr.sh +++ b/scripts/ocr.sh @@ -1,4 +1,41 @@ #!/bin/bash +# ----------------------------------------------------------------------------- +# WCX Thumbnail OCR +# +# Extracts text from a local image file or an image URL using the Google Cloud +# Vision API. +# +# The script: +# 1. Accepts either a local image path or an HTTP/HTTPS image URL. +# 2. Reads or downloads the image and encodes it as Base64. +# 3. Sends the image to Google Cloud Vision using TEXT_DETECTION. +# 4. Extracts the first detected text annotation from the API response. +# 5. Writes the OCR text to standard output or to a file specified with -o. +# +# Requirements: +# - GOOGLE_VISION_API_KEY must be set in the environment. +# - curl is required for HTTP requests and remote image downloads. +# - base64 is required for encoding the image. +# - jq is recommended and is required for clean plain-text output. +# +# Usage: +# ocr.sh [-o output-file] +# +# Examples: +# ./ocr.sh thumbnail.jpg +# ./ocr.sh "https://example.com/thumbnail.jpg" +# ./ocr.sh "https://example.com/thumbnail.jpg" -o ocr-result.txt +# +# Output contract: +# - Without -o, the detected OCR text is written to standard output. +# - With -o, the OCR text is written to the specified file and a completion +# message is written to standard output. +# - A non-zero exit status indicates invalid input, missing configuration, +# missing dependencies, an API failure, or that no text was detected. +# +# The output is raw OCR text. Its structure is not guaranteed by Google Vision +# and must be parsed and validated separately before being stored as metadata. +# ----------------------------------------------------------------------------- # --- KONFIGURATION --- # Skriptet förväntar sig nu miljövariabeln: GOOGLE_VISION_API_KEY