### Path Drawing Example Setup Source: https://docs.wand-py.org/en/0.6.12/_sources/guide/draw.rst Sets up drawing properties like stroke width and color, and fill color for subsequent path drawing operations. ```python from wand.image import Image from wand.drawing import Drawing from wand.color import Color with Drawing() as draw: draw.stroke_width = 2 draw.stroke_color = Color('black') draw.fill_color = Color('white') ``` -------------------------------- ### Install ImageMagick on Debian/Ubuntu Source: https://docs.wand-py.org/en/0.6.12/_sources/guide/install.rst Installs the ImageMagick development headers and libraries on Debian/Ubuntu systems using the APT package manager. This is a prerequisite for Wand. ```console sudo apt-get install libmagickwand-dev ``` -------------------------------- ### ImageMagick Library Suffix Pattern Source: https://docs.wand-py.org/en/0.6.12/_sources/guide/install.rst Illustrates the typical naming convention for ImageMagick shared libraries, which Wand uses to locate the correct files. This includes version, quantum, and HDRI information. ```text libMagickWand-7.Q16HDRI.so ``` -------------------------------- ### Development Dependencies Installation Source: https://docs.wand-py.org/en/0.6.12/_sources/whatsnew/0.6.rst Shows how to install additional development dependencies for Wand, including documentation and testing tools, using setuptools-extra. ```bash pip install -U Wand[doc,test] ``` -------------------------------- ### Install Wand on Debian/Ubuntu Source: https://docs.wand-py.org/en/0.6.12/_sources/guide/install.rst Installs the Wand Python library on Debian or Ubuntu systems using the apt-get package manager. This command fetches the pre-packaged version of python-wand from the APT repository. ```console sudo apt-get install python-wand ``` -------------------------------- ### Set MAGICK_HOME on Windows Source: https://docs.wand-py.org/en/0.6.12/_sources/guide/install.rst Sets the MAGICK_HOME environment variable on Windows to point to the ImageMagick installation directory. This is crucial for Wand to link correctly. ```console C:\\Users\\file ``` -------------------------------- ### Install Wand and Dependencies Source: https://docs.wand-py.org/en/0.6.12/_sources/index.rst Instructions for installing the Wand Python library and its underlying MagickWand library on Debian/Ubuntu systems. This involves installing development headers and then using pip. ```bash apt-get install libmagickwand-dev pip install Wand ``` -------------------------------- ### Install Wand using pip Source: https://docs.wand-py.org/en/0.6.12/_sources/guide/install.rst Installs the Wand library from PyPI using the pip package manager. This is the primary method for installing Wand in a Python environment. ```console pip install Wand ``` -------------------------------- ### Install ImageMagick with liblqr on Mac Source: https://docs.wand-py.org/en/0.6.12/_sources/guide/install.rst Installs ImageMagick with liblqr support using Homebrew on macOS. This is required for specific features like seam carving (liquid rescale). ```console brew install imagemagick --with-liblqr ``` -------------------------------- ### Example Pytest Configuration Source: https://docs.wand-py.org/en/0.6.12/test An example `pytest.ini` file demonstrating common configurations for Wand's nightly regression tests, including parallel execution and coverage reporting. ```ini [pytest] addopts=-n8 -rsfEw --cov wand --cov-report html ``` -------------------------------- ### Wand Installation Instructions Source: https://docs.wand-py.org/en/0.6.12/index Provides commands to install the necessary ImageMagick development libraries and the Wand Python package via pip. ```Shell apt-get install libmagickwand-dev pip install Wand ``` -------------------------------- ### Install ImageMagick on Mac with Homebrew Source: https://docs.wand-py.org/en/0.6.12/_sources/guide/install.rst Installs ImageMagick using the Homebrew package manager on macOS. This command installs the base ImageMagick package. ```console brew install imagemagick ``` -------------------------------- ### Install Wand on FreeBSD Source: https://docs.wand-py.org/en/0.6.12/_sources/guide/install.rst Installs the Wand Python library on FreeBSD systems using the pkg_add command. This command retrieves the py-wand package from the FreeBSD ports collection. ```console pkg_add -r py-wand ``` -------------------------------- ### Install Wand using pip Source: https://docs.wand-py.org/en/0.6.12/guide/install Installs the Wand Python library from the Python Package Index (PyPI) using pip. ```shell $ pip install Wand ``` -------------------------------- ### Example Pytest Configuration Source: https://docs.wand-py.org/en/0.6.12/_sources/test.rst An example configuration file for pytest, specifying parallel test execution (8 workers), verbose output, coverage reports, and specific coverage targets. ```ini [pytest] addopts=-n8 -rsfEw --cov wand --cov-report html ``` -------------------------------- ### Install ImageMagick on Mac with MacPorts Source: https://docs.wand-py.org/en/0.6.12/_sources/guide/install.rst Installs ImageMagick using the MacPorts package manager on macOS. This is an alternative to Homebrew for managing packages. ```console sudo port install imagemagick ``` -------------------------------- ### Install Wand on Alpine Linux Source: https://docs.wand-py.org/en/0.6.12/_sources/guide/install.rst Installs Wand on Alpine Linux using pip after installing ImageMagick via apk. It also requires setting the MAGICK_HOME environment variable to '/usr' and creating symbolic links for ImageMagick libraries. ```console # apk add imagemagick # pip install Wand # export MAGICK_HOME=/usr # ln -s /usr/lib/libMagickCore-7.Q16HDRI.so.9 /usr/lib/libMagickCore-7.Q16HDRI.so # ln -s /usr/lib/libMagickWand-7.Q16HDRI.so.9 /usr/lib/libMagickWand-7.Q16HDRI.so ``` -------------------------------- ### Install ImageMagick on Fedora/CentOS Source: https://docs.wand-py.org/en/0.6.12/_sources/guide/install.rst Installs ImageMagick development packages on Fedora/CentOS systems using the Yum package manager. This ensures ImageMagick is available for Wand. ```console yum update yum install ImageMagick-devel ``` -------------------------------- ### Install Development Dependencies Source: https://docs.wand-py.org/en/0.6.12/whatsnew/0.6 Installs the Wand library along with optional dependencies for documentation and testing using pip. This command ensures that users can access the full documentation and run regression tests locally. ```bash pip install -U Wand[doc,test] ``` -------------------------------- ### Install ImageMagick on Debian/Ubuntu Source: https://docs.wand-py.org/en/0.6.12/guide/install Installs the ImageMagick development libraries on Debian-based systems like Ubuntu using APT. ```shell $ sudo apt-get install libmagickwand-dev ``` -------------------------------- ### Install and Use Tox for Testing Source: https://docs.wand-py.org/en/0.6.12/_sources/test.rst Install the tox testing tool using pip. Tox automates testing across various Python implementations, ensuring compatibility. ```console $ pip install tox ``` -------------------------------- ### Add Distortion guide Source: https://docs.wand-py.org/en/0.6.12/_sources/changes.rst Completes and adds a new guide on image distortion techniques. This documentation provides detailed explanations and examples of how to apply various distortion effects. ```APIDOC Documentation: ./guide/distortion - New guide detailing image distortion methods and usage. ``` -------------------------------- ### Install and Run Wand Tests with Pytest Source: https://docs.wand-py.org/en/0.6.12/test Manually install the pytest testing framework and then run Wand's tests using the `pytest` command. This provides more granular control over test execution. ```shell $ pip install pytest $ pytest ``` -------------------------------- ### Install and Run Tests with Pytest Source: https://docs.wand-py.org/en/0.6.12/_sources/test.rst Manually install the pytest testing framework and then run tests using the pytest command. Pytest offers more advanced options for test execution. ```console $ pip install pytest $ pytest ``` -------------------------------- ### Install Wand on Alpine Linux Source: https://docs.wand-py.org/en/0.6.12/guide/install Installs Wand on Alpine Linux, which requires ImageMagick to be installed first via `apk`. It also necessitates setting the `MAGICK_HOME` environment variable and potentially creating symbolic links for ImageMagick libraries. ```bash # apk add imagemagick # pip install Wand # export MAGICK_HOME=/usr ``` ```bash # ln -s /usr/lib/libMagickCore-7.Q16HDRI.so.9 /usr/lib/libMagickCore-7.Q16HDRI.so # ln -s /usr/lib/libMagickWand-7.Q16HDRI.so.9 /usr/lib/libMagickWand-7.Q16HDRI.so ``` -------------------------------- ### Set WAND_MAGICK_LIBRARY_SUFFIX Environment Variable Source: https://docs.wand-py.org/en/0.6.12/_sources/guide/install.rst Demonstrates how to set the WAND_MAGICK_LIBRARY_SUFFIX environment variable, which is a semicolon-delimited list used to specify ImageMagick library versions. This is often required for specific configurations or when multiple versions are present. ```console export WAND_MAGICK_LIBRARY_SUFFIX="-7.Q32;-7.Q32HDRI;.Q32HDRI;.Q32" python3 wand_app.py ``` -------------------------------- ### Add Quantize guide Source: https://docs.wand-py.org/en/0.6.12/_sources/changes.rst Adds a comprehensive guide on image quantization. This documentation explains color quantization algorithms and how to reduce the number of colors in an image. ```APIDOC Documentation: ./guide/quantize - New guide detailing image quantization techniques. ``` -------------------------------- ### Install and Run Tests with Tox Source: https://docs.wand-py.org/en/0.6.12/test Install the tox testing tool using pip, which automates testing across multiple Python environments. Running `tox` in the project root tests Wand against various Python interpreters. ```shell $ pip install tox $ tox ``` -------------------------------- ### Add Threshold guide Source: https://docs.wand-py.org/en/0.6.12/_sources/changes.rst Creates a new guide explaining image thresholding techniques. This documentation covers different thresholding methods and their applications in image processing. ```APIDOC Documentation: ./guide/threshold - New guide detailing image thresholding methods. ``` -------------------------------- ### Install Wand on Debian/Ubuntu using apt-get Source: https://docs.wand-py.org/en/0.6.12/guide/install Installs the Wand Python library on Debian or Ubuntu systems using the APT package manager. This method assumes the `python-wand` package is available in the system's repositories. ```bash $ sudo apt-get install python-wand ``` -------------------------------- ### Image Annotation Example Source: https://docs.wand-py.org/en/0.6.12/_sources/changes.rst Mentions an update to the example in the docstring for the Image.annotate method. ```APIDOC Image.annotate(text, left=0, top=0, gravity=None, ...) - Adds text to the image. Updated example in docstring. ``` -------------------------------- ### Add Morphology guide Source: https://docs.wand-py.org/en/0.6.12/_sources/changes.rst Introduces a new guide focused on image morphology operations. This documentation covers techniques like erosion, dilation, opening, and closing for image analysis. ```APIDOC Documentation: ./guide/morphology - New guide detailing image morphology operations. ``` -------------------------------- ### Run Tests with setup.py Source: https://docs.wand-py.org/en/0.6.12/_sources/test.rst Execute the unit and regression tests for the Wand library using the setup.py script. This command also handles the installation of pytest if it's not already present. ```console $ python setup.py test ``` -------------------------------- ### Install Wand on Fedora Source: https://docs.wand-py.org/en/0.6.12/_sources/guide/install.rst Installs the Wand Python library on Fedora systems using the dnf package manager. It provides separate commands for Python 2 and Python 3 installations. ```console dnf install python-wand # Python 2 dnf install python3-wand # Python 3 ``` -------------------------------- ### Run Wand Tests with setup.py Source: https://docs.wand-py.org/en/0.6.12/test Execute the Wand library's tests using the standard `setup.py` script. This command automatically handles test discovery and execution, leveraging pytest. ```shell $ python setup.py test ``` -------------------------------- ### Set MAGICK_HOME on Mac (MacPorts) Source: https://docs.wand-py.org/en/0.6.12/_sources/guide/install.rst Sets the MAGICK_HOME environment variable on macOS when Python is not installed via MacPorts. This helps Wand locate the ImageMagick installation. ```console export MAGICK_HOME=/opt/local ``` -------------------------------- ### Initialize and Use Wand Drawing Object Source: https://docs.wand-py.org/en/0.6.12/_sources/guide/draw.rst Demonstrates how to initialize a Drawing object and apply its drawing instructions to an image. It shows the basic workflow of creating a drawing context and executing it on an image. ```python from wand.drawing import Drawing from wand.image import Image with Drawing() as draw: # does something with ``draw`` object, # and then... with Image(filename='wandtests/assets/beach.jpg') as image: draw(image) ``` -------------------------------- ### wand.image.Image Constructor and Methods Source: https://docs.wand-py.org/en/0.6.12/_sources/guide/read.rst API documentation for the `wand.image.Image` class, detailing its constructor parameters for opening images and key methods for manipulation. ```APIDOC wand.image.Image: __init__(filename=None, file=None, blob=None, width=None, height=None, format=None, background=None) Initializes an Image object. Parameters: filename (str, optional): Path to an image file. file (file-like object, optional): An input stream providing image binary data. blob (bytes or str, optional): Binary image data as a string or bytes. width (int, optional): Width for a new empty image. height (int, optional): Height for a new empty image. format (str, optional): Hint for the image format when reading from file or blob. background (wand.color.Color or str, optional): Background color for new empty images. Note: Parameters are mutually exclusive. Use `filename`, `file`, `blob`, or `width`/`height`. clone() -> Image Returns a copy of the image. Example: with original.clone() as copied_image: # Manipulate copied_image convert(format: str) -> Image Returns a new image converted to the specified format. Parameters: format (str): The target image format (e.g., 'png', 'jpeg'). Example: with original.convert('jpeg') as converted_image: # Use converted_image save(filename: str, format: str = None) Saves the image to a file. Parameters: filename (str): The path to save the image. format (str, optional): The format to save as. If None, inferred from filename. width (int): The width of the image. height (int): The height of the image. format (str): The image format (e.g., 'PNG', 'JPEG'). ``` -------------------------------- ### Example: Setting Resource Limits with wand.resource.ResourceLimits Source: https://docs.wand-py.org/en/0.6.12/wand/resource Demonstrates how to dynamically adjust ImageMagick resource limits like memory and image dimensions using the `ResourceLimits` class. It shows setting limits, accessing current usage, and iterating through all available limits. ```python from wand.image import Image from wand.resource import limits # Use 100MB of ram before writing temp data to disk. limits['memory'] = 1024 * 1024 * 100 # Reject images larger than 1000x1000. limits['width'] = 1000 limits['height'] = 1000 # Debug resources used. with Image(filename='user.jpg') as img: print('Using {0} of {1} memory'.format(limits.resource('memory'), limits['memory'])) # Dump list of all limits. for label in limits: print('{0} => {1}'.format(label, limits[label])) ``` -------------------------------- ### wand.resource.genesis() Source: https://docs.wand-py.org/en/0.6.12/wand Initializes the wand library's global resources. ```APIDOC genesis() Description: Initializes the wand library's global resource management system. ``` -------------------------------- ### Get Image Type - Python Source: https://docs.wand-py.org/en/0.6.12/guide/colorspace Retrieves the colorspace type of an image object. The type is an enumeration value that depends on the image's format. For example, 'grayscale' might not be available for JPEG images. ```python from wand.image import Image with Image(filename='wandtests/assets/bilevel.gif') as img: print(img.type) # Output: 'bilevel' with Image(filename='wandtests/assets/sasha.jpg') as img2: print(img2.type) # Output: 'truecolor' ``` -------------------------------- ### wand-py: Draw Lines Source: https://docs.wand-py.org/en/0.6.12/guide/draw Demonstrates drawing lines using the line() method, which takes start and end coordinates. The line color is determined by the fill_color property. Examples show drawing diagonal lines and changing line color. ```python from wand.drawing import Drawing from wand.color import Color # Assuming 'draw' is an instance of Drawing and 'image' is an Image object # draw.line((0, 0), image.size) # draw(image) # draw.line((0, image.height), (image.width, 0)) # draw(image) with Color('red') as color: draw.fill_color = color draw.line((0, 0), image.size) draw(image) ``` -------------------------------- ### wand-py: Get Image Quantum Range Source: https://docs.wand-py.org/en/0.6.12/wand/image A property that returns the maximum value of a color channel supported by the ImageMagick library. This is useful for understanding the bit depth and color precision of the underlying ImageMagick installation. Available from wand-py version 0.2.0. ```python quantum_range ``` -------------------------------- ### Install ImageMagick on Mac (Homebrew) Source: https://docs.wand-py.org/en/0.6.12/guide/install Installs ImageMagick on macOS using the Homebrew package manager. ```shell $ brew install imagemagick ``` -------------------------------- ### Install ImageMagick on Mac (MacPorts) Source: https://docs.wand-py.org/en/0.6.12/guide/install Installs ImageMagick on macOS using the MacPorts package manager. ```shell $ sudo port install imagemagick ``` -------------------------------- ### Basic Image Manipulation with Wand Source: https://docs.wand-py.org/en/0.6.12/_sources/index.rst Demonstrates loading an image, printing its size, resizing, rotating, saving, and displaying it using Wand. This example requires an image file named 'mona-lisa.png' in the same directory. ```python from wand.image import Image from wand.display import display with Image(filename='mona-lisa.png') as img: print(img.size) for r in 1, 2, 3: with img.clone() as i: i.resize(int(i.width * r * 0.25), int(i.height * r * 0.25)) i.rotate(90 * r) i.save(filename='mona-lisa-{0}.png'.format(r)) display(i) ``` -------------------------------- ### Install Wand on Fedora using dnf Source: https://docs.wand-py.org/en/0.6.12/guide/install Installs the Wand Python library on Fedora systems using the DNF package manager. Separate commands are provided for Python 2 and Python 3 installations. ```bash $ dnf install python-wand # Python 2 ``` ```bash $ dnf install python3-wand # Python 3 ``` -------------------------------- ### Initialize Wand Drawing Context Source: https://docs.wand-py.org/en/0.6.12/guide/draw Demonstrates how to initialize a Drawing object, buffer drawing instructions, and apply them to an image. This context manager ensures resources are properly handled. ```python from wand.drawing import Drawing from wand.image import Image with Drawing() as draw: # does something with ``draw`` object, # and then... with Image(filename='wandtests/assets/beach.jpg') as image: draw(image) ``` -------------------------------- ### Wand Image Manipulation Example Source: https://docs.wand-py.org/en/0.6.12/index Demonstrates basic image manipulation using the Wand library. It loads an image, resizes and rotates clones, and saves them. Requires the Wand library and ImageMagick. ```Python from wand.image import Image from wand.display import display with Image(filename='mona-lisa.png') as img: print(img.size) for r in 1, 2, 3: with img.clone() as i: i.resize(int(i.width * r * 0.25), int(i.height * r * 0.25)) i.rotate(90 * r) i.save(filename='mona-lisa-{0}.png'.format(r)) display(i) ``` -------------------------------- ### Install ImageMagick on Fedora/CentOS Source: https://docs.wand-py.org/en/0.6.12/guide/install Installs ImageMagick development packages on Red Hat-based systems like Fedora or CentOS using Yum. ```shell $ yum update $ yum install ImageMagick-devel ``` -------------------------------- ### Install Wand on FreeBSD using pkg_add Source: https://docs.wand-py.org/en/0.6.12/guide/install Installs the Wand Python library on FreeBSD systems using the `pkg_add` command. This method relies on the `py-wand` port being available in the FreeBSD ports collection. ```bash $ pkg_add -r py-wand ``` -------------------------------- ### wand.resource.genesis() Source: https://docs.wand-py.org/en/0.6.12/index Initializes the wand library's global resources. ```APIDOC genesis() Description: Initializes the wand library's global resource management system. ``` -------------------------------- ### Wand Drawing Stack Management Example Source: https://docs.wand-py.org/en/0.6.12/_sources/guide/draw.rst Demonstrates the use of push() and pop() methods in Wand's Drawing class to manage graphical context states, drawing lines with changing stroke colors. ```python from wand.color import Color from wand.image import Image from wand.drawing import Drawing from wand.compat import nested from math import cos, pi, sin with nested(Color('lightblue'), Color('transparent'), Drawing()) as (bg, fg, draw): draw.stroke_width = 3 draw.fill_color = fg for degree in range(0, 360, 15): draw.push() # Grow stack draw.stroke_color = Color('hsl({0}%, 100%, 50%)'.format(degree * 100 / 360)) t = degree / 180.0 * pi x = 35 * cos(t) + 50 y = 35 * sin(t) + 50 draw.line((50, 50), (x, y)) draw.pop() # Restore stack with Image(width=100, height=100, background=Color('lightblue')) as img: draw(img) ``` -------------------------------- ### Clone Wand Repository Source: https://docs.wand-py.org/en/0.6.12/index Instructions to clone the wand-py source code from its GitHub repository using Git. ```bash $ git clone git://github.com/emcconville/wand.git ``` -------------------------------- ### wand.drawing.Drawing Class and Methods Source: https://docs.wand-py.org/en/0.6.12/wand/drawing Documentation for the Drawing class and its methods, covering initialization, affine transformations, alpha channel manipulation, arc drawing, and bezier curves. ```APIDOC class wand.drawing.Drawing(drawing=None) Drawing object. It maintains several vector drawing instructions and can get drawn into zero or more Image objects by calling it. Example: with Drawing() as draw: draw.line((0, 0), image.size) draw(image) Parameters: drawing ([`Drawing`](#wand.drawing.Drawing "wand.drawing.Drawing")) – an optional drawing object to clone. use [`clone()`](#wand.drawing.Drawing.clone "wand.drawing.Drawing.clone") method rather than this parameter. New in version 0.3.0. affine(matrix) Adjusts the current affine transformation matrix with the specified affine transformation matrix. Note that the current affine transform is adjusted rather than replaced. Formula: | x', y', 1 | = | x, y, 1 | * | sx rx 0 | | ry sy 0 | | tx ty 1 | Parameters: matrix ([`collections.abc.Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence "(in Python v3.12)")) – a list of [`Real`](https://docs.python.org/3/library/numbers.html#numbers.Real "(in Python v3.12)") to define affine matrix `[sx, rx, ry, sy, tx, ty]` New in version 0.4.0. alpha(x=None, y=None, paint_method='undefined') Paints on the image’s opacity channel in order to set effected pixels to transparent. Available paint_methods: * 'undefined' * 'point' * 'replace' * 'floodfill' * 'filltoborder' * 'reset' Note: This method replaces [`matte()`](#wand.drawing.Drawing.matte "wand.drawing.Drawing.matte") in ImageMagick version 7. An [`AttributeError`](https://docs.python.org/3/library/exceptions.html#AttributeError "(in Python v3.12)") will be raised if attempting to call on a library without `DrawAlpha` support. New in version 0.5.0. arc(start, end, degree) Draws a arc using the current [`stroke_color`](#wand.drawing.Drawing.stroke_color "wand.drawing.Drawing.stroke_color"), [`stroke_width`](#wand.drawing.Drawing.stroke_width "wand.drawing.Drawing.stroke_width"), and [`fill_color`](#wand.drawing.Drawing.fill_color "wand.drawing.Drawing.fill_color"). Parameters: * start ([`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence "(in Python v3.12)")) – ([`Real`](https://docs.python.org/3/library/numbers.html#numbers.Real "(in Python v3.12)"), [`numbers.Real`](https://docs.python.org/3/library/numbers.html#numbers.Real "(in Python v3.12)")) pair which represents starting x and y of the arc * end ([`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence "(in Python v3.12)")) – ([`Real`](https://docs.python.org/3/library/numbers.html#numbers.Real "(in Python v3.12)"), [`numbers.Real`](https://docs.python.org/3/library/numbers.html#numbers.Real "(in Python v3.12)")) pair which represents ending x and y of the arc * degree ([`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence "(in Python v3.12)")) – ([`Real`](https://docs.python.org/3/library/numbers.html#numbers.Real "(in Python v3.12)"), [`numbers.Real`](https://docs.python.org/3/library/numbers.html#numbers.Real "(in Python v3.12)")) pair which represents starting degree, and ending degree New in version 0.4.0. bezier(points=None) Draws a bezier curve through a set of points on the image, using the specified array of coordinates. At least four points should be given to complete a bezier path. ``` -------------------------------- ### Set MAGICK_HOME for MacPorts Python Source: https://docs.wand-py.org/en/0.6.12/guide/install Exports the MAGICK_HOME environment variable for Python installations not managed by MacPorts, to locate ImageMagick libraries. ```shell $ export MAGICK_HOME=/opt/local ``` -------------------------------- ### Attribute Fixes and Guide Updates (Version 0.6.7) Source: https://docs.wand-py.org/en/0.6.12/changes Information on fixes for image attributes and new guide documentation for wand-py. ```APIDOC Image.background_color - Fixed attribute behavior when image was not read. Guide: Distortion - Completed guide documentation. Guide: Morphology - Added guide documentation. ``` -------------------------------- ### Wand-Py: Push & Pop Graphics Context Source: https://docs.wand-py.org/en/0.6.12/_sources/guide/draw.rst Explains the use of `push()` and related methods (`push_clip_path`, `push_defs`, `push_pattern`) to manage the graphics context stack. This allows for managing different styles and operations within complex vector graphics workflows, enabling sub-routine management. ```python # Example usage of push/pop for graphics context management # from wand.drawing import Drawing # # with Drawing() as draw: # draw.push() # Marks the beginning of a sub-routine # # Perform operations with a specific style # draw.fill_color = Color('red') # draw.rectangle((10, 10), (50, 50)) # draw.pop() # Restores the previous graphics context # # Perform operations with a different style # draw.fill_color = Color('blue') # draw.rectangle((60, 60), (100, 100)) # draw.pop() # Restores the context before the first push ``` -------------------------------- ### wand-py Version Configuration Source: https://docs.wand-py.org/en/0.6.12/genindex Information on how to configure wand-py version details. ```APIDOC Version Configuration: configure_options() - Retrieves configuration options for the wand library. - Belongs to module wand.version. ``` -------------------------------- ### Iterator First and Set Example Source: https://docs.wand-py.org/en/0.6.12/guide/sequence Demonstrates using iterator_first() to prepend an image to the stack and iterator_set() to move to specific frames. This allows for precise control over frame positioning and access. ```python >>> with Image(filename='support/link_net.gif') as img: ... img.iterator_first() ... img.pseudo(1, 1, 'xc:gold') ... img.iterator_set(0) ... print(img.size) ... img.iterator_set(1) ... print(img.size) (1, 1) (300, 289) ``` -------------------------------- ### README.rst Removal from setup.py Source: https://docs.wand-py.org/en/0.6.12/changes Notes the removal of README.rst from setup.py in version 0.6.0, as per issue #460. ```Python # Removed README.rst from setup.py. # [[#460](https://github.com/emcconville/wand/issues/460)] ``` -------------------------------- ### Wand-Py Connected Components Example Source: https://docs.wand-py.org/en/0.6.12/wand/image Example usage of the `connected_components` method from the Wand-Py library to identify and extract features of connected pixel groups within an image. ```python from wand.image import Image with Image(filename='objects.gif') as img: objects = img.connected_components() for cc_obj in objects: print("{0._id}: {0.size} {0.offset}".format(cc_obj)) ``` -------------------------------- ### Image Drawing and Text Wrapping Example Source: https://docs.wand-py.org/en/0.6.12/_sources/guide/draw.rst Demonstrates the usage of `draw_roi` and `word_wrap` functions. It initializes an image, sets drawing context properties, applies word wrapping to a message, draws the text, and saves the output image. ```Python message = "This is some really long sentence with the word \"Mississippi\" in it." ROI_SIDE = 175 with Image(filename='logo:') as img: with Drawing() as ctx: draw_roi(ctx, ROI_SIDE, ROI_SIDE) # Set the font style ctx.fill_color = Color('RED') ctx.font_family = 'Times New Roman' ctx.font_size = 32 mutable_message = word_wrap(img, ctx, message, ROI_SIDE, ROI_SIDE) ctx.text(75, 275, mutable_message) ctx.draw(img) img.save(filename='draw-word-wrap.png') ``` -------------------------------- ### Image Cropping Example Source: https://docs.wand-py.org/en/0.6.12/wand/image A practical Python code example demonstrating how to use image slicing to crop a specific region of an image and perform operations on the cropped portion. ```python with img[100:200, 150:300] as cropped: # manipulated the cropped image pass ``` -------------------------------- ### Apply Colors to Montage Components (Python) Source: https://docs.wand-py.org/en/0.6.12/guide/montage Demonstrates how to set `background_color`, `matte_color`, and `border_color` attributes on images to customize the appearance of montage elements. This example uses the `wand.image` module and iterates through pseudo-images to apply different frame and background colors before creating a montage. ```python from wand.image import Image with Image() as img: for src in ['pattern:crosshatch', 'canvas:orange', 'plasma:']: with Image(width=64, height=64, pseudo=src) as item: item.border_color = 'cyan' # Inner Frame item.matte_color = 'yellow' # Outer Frame img.image_add(item) img.background_color = 'magenta' # Canvas background img.montage(font=style) img.save(filename='montage-color.png') ``` -------------------------------- ### Affine Distortion Example Source: https://docs.wand-py.org/en/0.6.12/guide/distortion Provides a concrete example of affine distortion, which performs a shear operation. It uses 12 arguments to define three source-destination point pairs for the transformation. ```python from wand.color import Color from wand.image import Image with Image(filename='rose:') as img: img.resize(140, 92) img.background_color = Color('skyblue') img.virtual_pixel = 'background' args = ( 10, 10, 15, 15, # Point 1: (10, 10) => (15, 15) 139, 0, 100, 20, # Point 2: (139, 0) => (100, 20) 0, 92, 50, 80 # Point 3: (0, 92) => (50, 80) ) img.distort('affine', args) ``` -------------------------------- ### Using Resource with `with` statement Source: https://docs.wand-py.org/en/0.6.12/wand/resource Demonstrates how to use the `Resource` class with a `with` statement for automatic resource management. This pattern ensures that resources are properly allocated and cleaned up, even if errors occur. ```python from wand.resource import Resource class MyResource(Resource): '''My resource.''' def __init__(self): with self.allocate(): self.resource = library.NewResource() # Example usage: with MyResource() as resource: # use the resource... pass ``` -------------------------------- ### Get Image Dimensions (Python) Source: https://docs.wand-py.org/en/0.6.12/guide/resizecrop Retrieves the current width and height of an image using the `width` and `height` properties. These properties are read-only. The `size` property can also be used to get both dimensions as a tuple. ```Python from urllib.request import urlopen from wand.image import Image f = urlopen('http://pbs.twimg.com/profile_images/712673855341367296/WY6aLbBV_normal.jpg') with Image(file=f) as img: width = img.width height = img.height f.close() print(f"Width: {width}") print(f"Height: {height}") # Alternatively, get size as a tuple print(f"Size: {img.size}") ``` -------------------------------- ### Perform Image Resizing with Seam Carving using Wand Source: https://docs.wand-py.org/en/0.6.12/_sources/guide/resizecrop.rst Demonstrates how to use the `liquid_rescale` method in the Wand library to perform seam carving, allowing images to be resized without distortion. This example shows loading an image, performing a liquid rescale operation to a target size, and saving the result. ```python from wand.image import Image # Load an image with Image(filename='seam.jpg') as img: print(f"Original size: {img.size}") # Example 1: Resize using liquid_rescale with Image(filename='seam.jpg') as image_to_rescale: with image_to_rescale.clone() as resize_liquid: resize_liquid.liquid_rescale(234, 234) resize_liquid.save(filename='seam-liquid.jpg') print(f"Resized (liquid) size: {resize_liquid.size}") # Example 2: Standard resize (for comparison, not seam carving) with Image(filename='seam.jpg') as image_to_resize: with image_to_resize.clone() as resize_standard: resize_standard.resize(234, 234) resize_standard.save(filename='seam-resize.jpg') print(f"Resized (standard) size: {resize_standard.size}") # Example 3: Cropping (for comparison) with Image(filename='seam.jpg') as image_to_crop: with image_to_crop[:234, :] as crop_img: crop_img.save(filename='seam-crop.jpg') print(f"Cropped size: {crop_img.size}") ``` -------------------------------- ### wand.resource.Resource API Source: https://docs.wand-py.org/en/0.6.12/wand API documentation for resource management in wand-py, including allocation, destruction, and exception handling. ```APIDOC Resource Class Methods/Attributes: allocate() Description: Allocates the underlying resource. destroy() Description: Destroys the underlying resource. get_exception() Description: Retrieves any exception associated with the resource. raise_exception() Description: Raises an exception if one is associated with the resource. resource Description: Property to access the raw resource pointer. c_clear_exception() Description: Clears any C-level exception associated with the resource. c_destroy_resource() Description: Low-level C function to destroy the resource. c_get_exception() Description: Low-level C function to get the resource exception. c_is_resource() Description: Low-level C function to check if it's a valid resource. Error: DestroyedResourceError Description: Exception raised when attempting to access a destroyed resource. ``` -------------------------------- ### Wand Drawing API: Path Start and Finish Source: https://docs.wand-py.org/en/0.6.12/wand/drawing Defines the start and end of a path drawing sequence. All path commands must be enclosed within a path_start() and path_finish() pair, as they are subordinate commands. ```APIDOC path_start() Declares the start of a path drawing list which is terminated by a matching path_finish() command. All other path_* commands must be enclosed between a path_start() and a path_finish() command. New in version 0.4.0. path_finish() Terminates the current path drawing list. This command must be paired with a path_start() command. New in version 0.4.0. ``` -------------------------------- ### Sample Image (Python) Source: https://docs.wand-py.org/en/0.6.12/guide/resizecrop Scales an image to a desired size using the `sample()` method, which is generally faster than `resize()` for large images. It takes target width and height but does not support filter or blur options. It modifies the image in-place. ```Python from wand.image import Image with Image(filename='input.jpg') as img: print(f"Original size: {img.size}") # Sample to 50x60 pixels img.sample(50, 60) print(f"Sampled size: {img.size}") ``` -------------------------------- ### wand.image: Paper Size Mapping Example Source: https://docs.wand-py.org/en/0.6.12/wand/image Provides a dictionary mapping common paper size names to their dimensions in pixels at 72dpi. Includes a practical example demonstrating how to retrieve dimensions and create an image of that size. ```python from wand.image import Image, PAPERSIZE_MAP w, h = PAPERSIZE_MAP["a4"] with Image(width=w, height=h, background="white") as img: img.save(filename="a4_page.png") ``` -------------------------------- ### Recommended Image Resource Management Source: https://docs.wand-py.org/en/0.6.12/_sources/whatsnew/0.6.rst Illustrates the recommended practice for managing Wand Image resources using a 'with' statement to ensure proper memory deallocation. It also notes that omitting 'with' defers deallocation to Python's garbage collector. ```python from wand.image import Image # Recommended usage with 'with' statement for proper resource management with Image(filename='input.jpg') as img: # Image operations here pass # Usage without 'with' statement relies on Python's garbage collector # img = Image(filename='input.jpg') # ... operations ... # del img # or rely on gc.collect() ```