{"id":8235,"library":"invisible-watermark","title":"Invisible Watermark","description":"Invisible Watermark is a Python library designed for robustly embedding and extracting invisible watermarks within images. It provides functionalities to encode arbitrary text or data into an image without perceptibly altering its visual appearance, and subsequently decode the hidden information. The library is actively developed, currently at version 0.2.0, with releases occurring periodically to introduce features and fixes.","status":"active","version":"0.2.0","language":"en","source_language":"en","source_url":"https://github.com/ShieldMnt/invisible-watermark","tags":["watermark","image-processing","steganography","security"],"install":[{"cmd":"pip install invisible-watermark","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"InvisibleWatermark","correct":"from invisible_watermark import InvisibleWatermark"}],"quickstart":{"code":"import os\nfrom PIL import Image\nfrom invisible_watermark import InvisibleWatermark\n\n# 1. Create a dummy image for demonstration if it doesn't exist\nimage_filename = \"dummy_input_image.png\"\noutput_filename = \"dummy_watermarked_image.png\"\n\nif not os.path.exists(image_filename):\n    img = Image.new('RGB', (256, 256), color = 'red')\n    img.save(image_filename)\n    print(f\"Created dummy image: {image_filename}\")\n\n# 2. Initialize the watermark library\niwm = InvisibleWatermark()\n\n# 3. Define the watermark text\nwatermark_text = \"SecretMessage123\"\nprint(f\"Original watermark: {watermark_text}\")\n\n# 4. Encode the watermark into the image\niwm.encode(image_filename, output_filename, watermark_text)\nprint(f\"Watermark encoded and saved to: {output_filename}\")\n\n# 5. Decode the watermark from the watermarked image\ndecoded_text = iwm.decode(output_filename)\nprint(f\"Decoded watermark: {decoded_text}\")\n\n# 6. Clean up generated files (optional)\n# os.remove(image_filename)\n# os.remove(output_filename)","lang":"python","description":"This quickstart demonstrates how to create a dummy image, then initialize the InvisibleWatermark library to encode a text watermark into it, and finally decode the watermark from the saved output image."},"warnings":[{"fix":"Ensure `opencv-python` (or `opencv-python-headless` for server environments) is successfully installed. You may need to manually verify `import cv2` works. For persistent issues, consult OpenCV installation guides for your specific OS/architecture.","message":"The library heavily relies on `opencv-python` for image processing. Installation of `opencv-python` can sometimes be challenging or lead to `ModuleNotFoundError: No module named 'cv2'` on certain systems (e.g., ARM processors, headless servers without GUI dependencies).","severity":"gotcha","affected_versions":"0.1.x - 0.2.x"},{"fix":"Always double-check image paths for correctness (absolute vs. relative). Prior to using the library, verify images are readable by OpenCV: `import cv2; img = cv2.imread('your_image.jpg'); if img is None: print('Failed to load image')`.","message":"The `encode` method expects image paths that `cv2.imread()` can successfully load. Using incorrect file paths, unsupported image formats, or corrupted images will result in failures or `NoneType` errors.","severity":"gotcha","affected_versions":"0.1.x - 0.2.x"},{"fix":"It is recommended to pin your `invisible-watermark` version in your `requirements.txt` (e.g., `invisible-watermark==0.2.0`) and review release notes or the GitHub repository for any breaking changes before upgrading.","message":"As an early-stage library (version 0.2.0), the API is still evolving. While specific breaking changes weren't extensively documented between 0.1.x and 0.2.x, future minor or patch versions could introduce them without comprehensive migration guides.","severity":"gotcha","affected_versions":"0.x"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install `opencv-python` using pip: `pip install opencv-python`. If you are in a headless environment, try `pip install opencv-python-headless`.","cause":"The `opencv-python` package, which provides the `cv2` module, is either not installed or not correctly installed in your environment.","error":"ModuleNotFoundError: No module named 'cv2'"},{"fix":"Verify that the image path is correct and the file exists. Check if the image file is valid and readable by OpenCV by trying to load it directly with `cv2.imread()` in a Python interpreter.","cause":"`cv2.imread()` returned `None` because the specified image file could not be found, is corrupted, or is in an unsupported format. The library then attempts to access attributes of this `None` object.","error":"AttributeError: 'NoneType' object has no attribute 'shape'"},{"fix":"Ensure that the input image is a color image. If you have a grayscale image, convert it to a 3-channel image before passing it to `iwm.encode()`, for example: `import cv2; gray_img = cv2.imread('gray.png', cv2.IMREAD_GRAYSCALE); color_img = cv2.cvtColor(gray_img, cv2.COLOR_GRAY2BGR)`.","cause":"This typically occurs when the library expects a multi-channel image (e.g., BGR) but receives a single-channel grayscale image or an image with unexpected dimensions.","error":"IndexError: too many indices for array"}]}