{"id":3317,"library":"wand","title":"Wand","description":"Wand is a ctypes-based simple ImageMagick binding for Python. It provides a Pythonic interface to the MagickWand API, enabling comprehensive image manipulation tasks such as resizing, cropping, rotating, applying effects, and converting between various image formats. The current version is 0.7.0, and it is actively maintained with regular releases.","status":"active","version":"0.7.0","language":"en","source_language":"en","source_url":"https://github.com/emcconville/wand","tags":["image processing","imagemagick","graphics","image manipulation"],"install":[{"cmd":"pip install wand","lang":"bash","label":"Install Wand"}],"dependencies":[{"reason":"Wand is a Python binding for the ImageMagick C library and requires a system-wide installation of ImageMagick.","package":"ImageMagick","optional":false},{"reason":"Development headers for ImageMagick are often required for Wand to link correctly on Linux distributions.","package":"libmagickwand-dev","optional":true},{"reason":"Required for rendering PDF files or using FreeType font features with ImageMagick.","package":"ghostscript","optional":true}],"imports":[{"note":"Importing '*' is discouraged in production code. Explicitly import 'Image' from 'wand.image' for clarity and to avoid namespace pollution.","wrong":"from wand import *","symbol":"Image","correct":"from wand.image import Image"}],"quickstart":{"code":"import os\nfrom wand.image import Image\n\n# Create a dummy image file for demonstration if it doesn't exist\ndummy_image_path = 'example.jpg'\nif not os.path.exists(dummy_image_path):\n    try:\n        # Using a minimal Pillow to create a dummy image if Wand can't (no ImageMagick installed yet)\n        from PIL import Image as PImage\n        PImage.new('RGB', (400, 300), color = 'red').save(dummy_image_path)\n        print(f\"Created a dummy image: {dummy_image_path}\")\n    except ImportError:\n        print(\"Please create an 'example.jpg' file or install Pillow (pip install Pillow) to run this quickstart.\")\n        exit()\n\n# Ensure ImageMagick can be found if MAGICK_HOME is needed (e.g., on some macOS/Windows installs)\n# os.environ['MAGICK_HOME'] = '/opt/homebrew' # Example for Homebrew on macOS\n\ntry:\n    with Image(filename=dummy_image_path) as img:\n        print(f\"Original size: {img.width}x{img.height}\")\n\n        # Resize the image to 200x150 pixels\n        img.resize(200, 150)\n        output_path = 'resized_example.jpg'\n        img.save(filename=output_path)\n        print(f\"Resized image saved to {output_path} with size: {img.width}x{img.height}\")\n\n        # Apply a blur effect\n        img.blur(radius=0, sigma=3)\n        blurred_output_path = 'blurred_example.jpg'\n        img.save(filename=blurred_output_path)\n        print(f\"Blurred image saved to {blurred_output_path}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Make sure ImageMagick is installed and correctly configured (e.g., MAGICK_HOME environment variable).\")\n","lang":"python","description":"This quickstart demonstrates how to load an image, resize it, and apply a blur effect using Wand. It also includes error handling and a method to create a dummy image for testing if one isn't available. Ensure ImageMagick is installed on your system for Wand to function."},"warnings":[{"fix":"Upgrade to Python 3.8 or higher. For projects requiring Python 2, use Wand < 0.7.0, though this is not recommended due to lack of security updates.","message":"Wand 0.7.0 removed support for Python 2. All Python 2 compatibility code has been eliminated.","severity":"breaking","affected_versions":">=0.7.0"},{"fix":"Install ImageMagick system-wide. For Debian/Ubuntu, use `sudo apt-get install imagemagick libmagickwand-dev`. For macOS (Homebrew), use `brew install imagemagick`. On Windows, download a prebuilt binary and ensure 'Install development headers and libraries for C and C++' is checked.","message":"Wand is a binding to the ImageMagick C library and requires ImageMagick to be installed on your system. It does not ship with ImageMagick itself.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Set the `MAGICK_HOME` environment variable to the path where ImageMagick is installed (e.g., `export MAGICK_HOME=/opt/homebrew` on macOS or `set MAGICK_HOME=C:\\Program Files\\ImageMagick-7.0.x-Q16` on Windows).","message":"For some installations (e.g., Homebrew on Apple Silicon macOS, or custom ImageMagick paths on Windows/Linux), you may need to set the `MAGICK_HOME` environment variable to the ImageMagick installation directory for Wand to find it.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always use `with Image(filename='...') as img:` when working with image objects to ensure proper resource cleanup. If not using `with`, explicitly call `img.close()` when done.","message":"Failing to use the `with` statement (context manager) with `wand.image.Image` objects, or manually calling `.close()`, can lead to memory leaks, especially in long-running applications.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Specify the desired resolution explicitly when opening a PDF: `with Image(filename='input.pdf', resolution=300) as img:`. This ensures Wand processes the PDF at the intended quality.","message":"When processing PDFs, Wand defaults to a resolution of 72 DPI. If the original PDF has a higher resolution or if high-quality output is needed, this default can lead to significant quality degradation or unexpected scaling issues.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}