{"library":"pytesseract","code":"import pytesseract\nfrom PIL import Image\nimport os\n\n# Ensure Tesseract-OCR is installed and in your system's PATH.\n# If not, you may need to specify the path to the tesseract executable:\n# pytesseract.pytesseract.tesseract_cmd = r'C:\\Program Files\\Tesseract-OCR\\tesseract.exe' # Example for Windows\n# pytesseract.pytesseract.tesseract_cmd = r'/usr/local/bin/tesseract' # Example for macOS\n\n# Create a dummy image file for demonstration\ntry:\n    from PIL import ImageDraw, ImageFont\n    img = Image.new('RGB', (200, 50), color = (255, 255, 255))\n    d = ImageDraw.Draw(img)\n    fnt = ImageFont.truetype(os.environ.get('FONT_PATH', 'arial.ttf'), 20) # Use a common font or provide path\n    d.text((10,10), \"Hello World\", font=fnt, fill=(0,0,0))\n    img.save('test_image.png')\n    image_path = 'test_image.png'\nexcept ImportError:\n    print(\"Pillow is missing drawing capabilities, cannot create test image. Please ensure you have a full Pillow install.\")\n    # Fallback for systems without font support (e.g., some CI environments)\n    # This part would typically be replaced by loading an actual image file.\n    image_path = os.environ.get('TEST_IMAGE_PATH', 'non_existent_image.png') # For testing without generating image\n\nif os.path.exists(image_path):\n    try:\n        text = pytesseract.image_to_string(Image.open(image_path))\n        print(f\"Extracted text: {text.strip()}\")\n    except Exception as e:\n        print(f\"Error during OCR: {e}\")\n        print(\"Please ensure Tesseract-OCR is installed and configured correctly.\")\nelse:\n    print(f\"Test image '{image_path}' not found. Please provide one or install font for auto-generation.\")\n","lang":"python","description":"This quickstart demonstrates how to extract text from an image using `pytesseract.image_to_string`. It requires the Tesseract-OCR engine to be installed and accessible. It also includes a robust way to create a dummy image if needed, for demonstration purposes.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}