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.
pip install wandVerified import paths — ran on the pinned version, not inferred.
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.
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.
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.
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).
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.
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.
Install ImageMagick on your operating system (e.g., `sudo apt-get install imagemagick libmagickwand-dev` on Debian/Ubuntu, `brew install imagemagick` on macOS, or download from imagemagick.org for Windows and ensure it's in your system PATH).
Ensure ImageMagick is installed on your Windows system and that its 'bin' directory (e.g., C:\Program Files\ImageMagick-7.X.X-QXX\bin) is added to your system's PATH environment variable.
Verify that the input file path is correct, the file itself is a valid and uncorrupted JPEG image, and that its content matches the expected format. Ensure you're passing correct image data (file path or bytes) to the `Image` constructor.
Reduce the image's dimensions or resolution, process images in smaller batches, free up system memory, or ensure image objects are properly disposed using `with Image(...) as img:` or `img.destroy()` to release resources.