Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def type(self):
"""(:class:`basestring`) The image type.
Defines image type as in :const:`IMAGE_TYPES` enumeration.
It may raise :exc:`ValueError` when the type is unknown.
.. versionadded:: 0.2.2
"""
image_type_index = library.MagickGetImageType(self.wand)
if not image_type_index:
self.raise_exception()
return IMAGE_TYPES[text(image_type_index)]
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
#:
#: Set to empty string if the system uses an older version of
#: ImageMagick-6, or does not support :c:func:`GetMagickDelegates`.
#:
#: .. versionadded:: 0.5.0
if libmagick.GetMagickDelegates: # pragma: no cover
MAGICK_VERSION_DELEGATES = text(libmagick.GetMagickDelegates())
else: # pragma: no cover
MAGICK_VERSION_DELEGATES = ""
#: (:class:`basestring`) A string of all features enabled.
#: This value is identical to what is returned by
#: :c:func:`GetMagickFeatures`
#:
#: .. versionadded:: 0.5.0
MAGICK_VERSION_FEATURES = text(libmagick.GetMagickFeatures())
#: (:class:`tuple`) The version tuple e.g. ``(6, 7, 7, 6)`` of
#: :const:`MAGICK_VERSION`.
#:
#: .. versionadded:: 0.2.1
MAGICK_VERSION_INFO = tuple(int(v or 0) for v in _match.groups())
#: (:class:`basestring`) The date string e.g. ``'2012-06-03'`` of
#: :const:`MAGICK_RELEASE_DATE_STRING`. This value is the exactly same
#: string to the result of :c:func:`GetMagickReleaseDate` function.
#:
#: .. versionadded:: 0.2.1
MAGICK_RELEASE_DATE_STRING = text(libmagick.GetMagickReleaseDate())
if MAGICK_RELEASE_DATE_STRING:
_match = re.match(r'^(\d{4})-?(\d\d)-?(\d\d)$',
#: .. versionadded:: 0.2.1
MAGICK_VERSION_NUMBER = c_magick_version.value
_match = re.match(r'^ImageMagick\s+(\d+)\.(\d+)\.(\d+)(?:-(\d+))?',
MAGICK_VERSION)
#: (:class:`basestring`) A string of all delegates enabled.
#: This value is identical to what is returned by
#: :c:func:`GetMagickDelegates`
#:
#: Set to empty string if the system uses an older version of
#: ImageMagick-6, or does not support :c:func:`GetMagickDelegates`.
#:
#: .. versionadded:: 0.5.0
if libmagick.GetMagickDelegates: # pragma: no cover
MAGICK_VERSION_DELEGATES = text(libmagick.GetMagickDelegates())
else: # pragma: no cover
MAGICK_VERSION_DELEGATES = ""
#: (:class:`basestring`) A string of all features enabled.
#: This value is identical to what is returned by
#: :c:func:`GetMagickFeatures`
#:
#: .. versionadded:: 0.5.0
MAGICK_VERSION_FEATURES = text(libmagick.GetMagickFeatures())
#: (:class:`tuple`) The version tuple e.g. ``(6, 7, 7, 6)`` of
#: :const:`MAGICK_VERSION`.
#:
#: .. versionadded:: 0.2.1
MAGICK_VERSION_INFO = tuple(int(v or 0) for v in _match.groups())
: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
def __iter__(self):
image = self.image
num = ctypes.c_size_t()
props_p = library.MagickGetImageProperties(image.wand, b'', num)
props = [text(props_p[i]) for i in xrange(num.value)]
library.MagickRelinquishMemory(props_p)
return iter(props)
def __getitem__(self, color):
if self.counts is None:
string = library.PixelGetColorAsNormalizedString
pixels = self.pixels
count = library.PixelGetColorCount
self.counts = dict(
(text(string(pixels[i]).value), count(pixels[i]))
for i in xrange(self.size.value)
)
del self.size, self.pixels
return self.counts[color.normalized_string]
:type gravity: :class:`basestring`
.. versionadded:: 0.3.0
"""
if not isinstance(left, numbers.Integral):
raise TypeError('left must be an integer, not ' + repr(left))
elif not isinstance(top, numbers.Integral):
raise TypeError('top must be an integer, not ' + repr(top))
elif width is not None and not isinstance(width, numbers.Integral):
raise TypeError('width must be an integer, not ' + repr(width))
elif height is not None and not isinstance(height, numbers.Integral):
raise TypeError('height must be an integer, not ' + repr(height))
elif font is not None and not isinstance(font, Font):
raise TypeError('font must be a wand.font.Font, not ' + repr(font))
elif gravity is not None and compat.text(gravity) not in GRAVITY_TYPES:
raise ValueError('invalid gravity value')
if width is None:
width = self.width - left
if height is None:
height = self.height - top
with Image() as textboard:
library.MagickSetSize(textboard.wand, width, height)
textboard.font = font or self.font
textboard.gravity = gravity or self.gravity
with Color('transparent') as background_color:
library.MagickSetBackgroundColor(textboard.wand,
background_color.resource)
textboard.read(filename=b'caption:' + text.encode('utf-8'))
self.composite(textboard, left, top)