How to use the wand.compat.binary function in Wand

To help you get started, we’ve selected a few Wand examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github emcconville / wand / wand / drawing.py View on Github external
:type left: :class:`numbers.Real`
        :param top: y ordinate of top left corner.
        :type top: :class:`numbers.Real`
        :param width: width of pattern space.
        :type width: :class:`numbers.Real`
        :param height: height of pattern space.
        :type height: :class:`numbers.Real`
        :returns: success of push operation
        :rtype: `bool`

        .. versionadded:: 0.4.0

        """
        assertions.assert_string(pattern_id=pattern_id)
        assertions.assert_real(left=left, top=top, width=width, height=height)
        okay = library.DrawPushPattern(self.resource, binary(pattern_id),
                                       left, top,
                                       width, height)
        return bool(okay)
github emcconville / wand / wand / drawing.py View on Github external
def font_family(self, family):
        assertions.assert_string(font_family=family)
        library.DrawSetFontFamily(self.resource, binary(family))
github emcconville / wand / wand / image.py View on Github external
def __setitem__(self, key, value):
        if not isinstance(key, string_type):
            raise TypeError('option name must be a string, not ' + repr(key))
        if not isinstance(value, string_type):
            raise TypeError('option value must be a string, not ' +
                            repr(value))
        if key not in OPTIONS:
            raise ValueError('invalid option: ' + repr(key))
        image = self.image
        library.MagickSetOption(image.wand, binary(key), binary(value))
github emcconville / wand / wand / drawing.py View on Github external
def vector_graphics(self, vector_graphics):
        if vector_graphics is not None and not isinstance(vector_graphics,
                                                          string_type):
            raise TypeError('expected a string, not ' + repr(vector_graphics))
        elif vector_graphics is None:
            # Reset all vector graphic properties on drawing wand.
            library.DrawResetVectorGraphics(self.resource)
        else:
            vector_graphics = binary(vector_graphics)
            okay = library.DrawSetVectorGraphics(self.resource,
                                                 vector_graphics)
            if okay == 0:  # pragma: no cover
                raise ValueError("Vector graphic not understood.")
github emcconville / wand / wand / version.py View on Github external
Example: List supported PNG formats::

        >>> from wand.version import formats
        >>> formats('PNG*')
        ['PNG', 'PNG00', 'PNG8', 'PNG24', 'PNG32', 'PNG48', 'PNG64']


    :param pattern: A term to filter formats against. Supports wildcards '*'
                    characters. Default pattern '*' for all formats.
    :type pattern: :class:`basestring`
    :returns: Sequence of matching formats
    :rtype: :class:`collections.Sequence`
    """
    if not isinstance(pattern, string_type):
        raise TypeError('pattern must be a string, not ' + repr(pattern))
    pattern_p = ctypes.create_string_buffer(binary(pattern))
    number_formats = ctypes.c_size_t(0)
    formats = []
    formats_p = library.MagickQueryFormats(pattern_p,
                                           ctypes.byref(number_formats))
    cursor = 0
    while cursor < number_formats.value:
        value = formats_p[cursor].value
        formats.append(text(value))
        cursor += 1
    return formats
github emcconville / wand / wand / version.py View on Github external
>>> from wand.version import fonts
        >>> fonts('*Helvetica*Bold*')
        ['Helvetica-Bold', 'Helvetica-Bold-Oblique', 'Helvetica-BoldOblique',
         'Helvetica-Narrow-Bold', 'Helvetica-Narrow-BoldOblique']


    :param pattern: A term to filter queries against. Supports wildcard '*'
                    characters. Default patterns '*' for all options.
    :type pattern: :class:`basestring`
    :returns: Sequence of matching fonts
    :rtype: :class:`collections.Sequence`
    """
    if not isinstance(pattern, string_type):
        raise TypeError('pattern must be a string, not ' + repr(pattern))
    pattern_p = ctypes.create_string_buffer(binary(pattern))
    number_fonts = ctypes.c_size_t(0)
    fonts = []
    fonts_p = library.MagickQueryFonts(pattern_p,
                                       ctypes.byref(number_fonts))
    cursor = 0
    while cursor < number_fonts.value:
        font = fonts_p[cursor].value
        fonts.append(text(font))
        cursor += 1
    return fonts
github emcconville / wand / wand / image.py View on Github external
def format(self, fmt):
        if not isinstance(fmt, string_type):
            raise TypeError("format must be a string like 'png' or 'jpeg'"
                            ', not ' + repr(fmt))
        fmt = fmt.strip()
        r = library.MagickSetImageFormat(self.wand, binary(fmt.upper()))
        if not r:
            raise ValueError(repr(fmt) + ' is unsupported format')
        r = library.MagickSetFilename(self.wand,
                                      b'buffer.' + binary(fmt.lower()))
        if not r:
            self.raise_exception()
github emcconville / wand / wand / drawing.py View on Github external
"""Sets the pattern used for stroking object outlines. Only local
        URLs ("#identifier") are supported at this time. These local URLs are
        normally created by defining a named stroke pattern with
        Drawing.push_pattern & Drawing.pop_pattern.

        :param url: URL to use to obtain stroke pattern.
        :type url: :class:`basestring`

        .. versionadded:: 0.4.0

        """
        assertions.assert_string(url=url)
        if url[0] != '#':
            raise ValueError('value not a relative URL, '
                             'expecting "#identifier"')
        okay = library.DrawSetStrokePatternURL(self.resource, binary(url))
        if okay == 0:
            # ThrowDrawException(DrawError,"URLNotFound",fill_url)
            self.raise_exception()
github emcconville / wand / wand / version.py View on Github external
Example: Find where the ImageMagick documents are installed::

        >>> from wand.version import configure_options
        >>> configure_options('DOC*')
        {'DOCUMENTATION_PATH': '/usr/local/share/doc/ImageMagick-6'}

    :param pattern: A term to filter queries against. Supports wildcard '*'
                    characters. Default patterns '*' for all options.
    :type pattern: :class:`basestring`
    :returns: Directory of configuration options matching given pattern
    :rtype: :class:`collections.defaultdict`
    """
    if not isinstance(pattern, string_type):
        raise TypeError('pattern must be a string, not ' + repr(pattern))
    pattern_p = ctypes.create_string_buffer(binary(pattern))
    config_count = ctypes.c_size_t(0)
    configs = {}
    configs_p = library.MagickQueryConfigureOptions(pattern_p,
                                                    ctypes.byref(config_count))
    cursor = 0
    while cursor < config_count.value:
        config = configs_p[cursor].value
        value = library.MagickQueryConfigureOption(config)
        configs[text(config)] = text(value.value)
        cursor += 1
    return configs
github emcconville / wand / wand / drawing.py View on Github external
def push_clip_path(self, clip_mask_id):
        """Starts a clip path definition which is comprised of any number of
        drawing commands and terminated by a :class:`Drawing.pop_clip_path`
        command.

        :param clip_mask_id: string identifier to associate with the clip path.
        :type clip_mask_id: :class:`basestring`

        .. versionadded:: 0.4.0

        """
        library.DrawPushClipPath(self.resource, binary(clip_mask_id))