Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
drawing(image)
is equivalent to the following code which calls :meth:`draw()` method::
drawing.draw(image)
:param image: the image to be drawn
:type image: :class:`~wand.image.BaseImage`
"""
if not isinstance(image, BaseImage):
raise TypeError('image must be a wand.image.BaseImage instance,'
' not ' + repr(image))
if isinstance(image, SingleImage):
previous = library.MagickGetIteratorIndex(image.container.wand)
library.MagickSetIteratorIndex(image.container.wand, image.index)
res = library.MagickDrawImage(image.container.wand, self.resource)
library.MagickSetIteratorIndex(image.container.wand, previous)
else:
res = library.MagickDrawImage(image.wand, self.resource)
if not res:
self.raise_exception()
try:
filter = FILTER_TYPES.index(filter)
except IndexError:
raise ValueError(repr(filter) + ' is an invalid filter type; '
'choose on in ' + repr(FILTER_TYPES))
elif (isinstance(filter, numbers.Integral) and
not (0 <= filter < len(FILTER_TYPES))):
raise ValueError(repr(filter) + ' is an invalid filter type')
blur = ctypes.c_double(float(blur))
if self.animation:
self.wand = library.MagickCoalesceImages(self.wand)
library.MagickSetLastIterator(self.wand)
n = library.MagickGetIteratorIndex(self.wand)
library.MagickResetIterator(self.wand)
for i in xrange(n + 1):
library.MagickSetIteratorIndex(self.wand, i)
library.MagickResizeImage(self.wand, width, height,
filter, blur)
library.MagickSetSize(self.wand, width, height)
else:
r = library.MagickResizeImage(self.wand, width, height,
filter, blur)
library.MagickSetSize(self.wand, width, height)
if not r:
self.raise_exception()
:param transparency: the percentage fade that should be performed on
the image, from 0.0 to 1.0
:type transparency: :class:`numbers.Real`
.. versionadded:: 0.2.0
"""
if transparency:
t = ctypes.c_double(float(self.quantum_range *
float(transparency)))
if t.value > self.quantum_range or t.value < 0:
raise ValueError('transparency must be a numbers.Real value ' +
'between 0.0 and 1.0')
# Set the wand to image zero, in case there are multiple images
# in it
library.MagickSetIteratorIndex(self.wand, 0)
# Change the pixel representation of the image
# to RGB with an alpha channel
library.MagickSetImageType(self.wand,
IMAGE_TYPES.index('truecolormatte'))
# Perform the black channel subtraction
library.MagickEvaluateImageChannel(self.wand,
CHANNELS['opacity'],
EVALUATE_OPS.index('subtract'),
t)
self.raise_exception()
is equivalent to the following code which calls :meth:`draw()` method::
drawing.draw(image)
:param image: the image to be drawn
:type image: :class:`~wand.image.BaseImage`
"""
if not isinstance(image, BaseImage):
raise TypeError('image must be a wand.image.BaseImage instance,'
' not ' + repr(image))
if isinstance(image, SingleImage):
previous = library.MagickGetIteratorIndex(image.container.wand)
library.MagickSetIteratorIndex(image.container.wand, image.index)
res = library.MagickDrawImage(image.container.wand, self.resource)
library.MagickSetIteratorIndex(image.container.wand, previous)
else:
res = library.MagickDrawImage(image.wand, self.resource)
if not res:
self.raise_exception()
if background is None:
background = Color('transparent')
elif not isinstance(background, Color):
raise TypeError('background must be a wand.color.Color instance, '
'not ' + repr(background))
if not isinstance(degree, numbers.Real):
raise TypeError('degree must be a numbers.Real value, not ' +
repr(degree))
with background:
if self.animation:
self.wand = library.MagickCoalesceImages(self.wand)
library.MagickSetLastIterator(self.wand)
n = library.MagickGetIteratorIndex(self.wand)
library.MagickResetIterator(self.wand)
for i in range(0, n + 1):
library.MagickSetIteratorIndex(self.wand, i)
library.MagickRotateImage(self.wand,
background.resource,
degree)
if reset_coords:
library.MagickResetImagePage(self.wand, None)
else:
result = library.MagickRotateImage(self.wand,
background.resource,
degree)
if not result:
self.raise_exception()
if reset_coords:
self.reset_coords()
# Also verify that only ASCII characters are included
try:
crop = crop.encode('ascii')
except UnicodeEncodeError:
raise ValueError('crop must only contain ascii-encodable ' +
'characters.')
try:
resize = resize.encode('ascii')
except UnicodeEncodeError:
raise ValueError('resize must only contain ascii-encodable ' +
'characters.')
if self.animation:
new_wand = library.MagickCoalesceImages(self.wand)
length = len(self.sequence)
for i in xrange(length):
library.MagickSetIteratorIndex(new_wand, i)
if i:
library.MagickAddImage(
new_wand,
library.MagickTransformImage(new_wand, crop, resize)
)
else:
new_wand = library.MagickTransformImage(new_wand,
crop,
resize)
self.sequence.instances = []
else:
new_wand = library.MagickTransformImage(self.wand, crop, resize)
if not new_wand:
self.raise_exception()
self.wand = new_wand
elif not isinstance(height, numbers.Integral):
raise TypeError('height must be a natural number, not ' +
repr(height))
elif width < 1:
raise ValueError('width must be a natural number, not ' +
repr(width))
elif height < 1:
raise ValueError('height must be a natural number, not ' +
repr(height))
if self.animation:
self.wand = library.MagickCoalesceImages(self.wand)
library.MagickSetLastIterator(self.wand)
n = library.MagickGetIteratorIndex(self.wand)
library.MagickResetIterator(self.wand)
for i in xrange(n + 1):
library.MagickSetIteratorIndex(self.wand, i)
library.MagickSampleImage(self.wand, width, height)
library.MagickSetSize(self.wand, width, height)
else:
r = library.MagickSampleImage(self.wand, width, height)
library.MagickSetSize(self.wand, width, height)
if not r:
self.raise_exception()
slice_ = self.validate_slice(index)
return [self[i] for i in xrange(slice_.start, slice_.stop)]
index = self.validate_position(index)
instances = self.instances
instances_length = len(instances)
if index < instances_length:
instance = instances[index]
if (instance is not None and
getattr(instance, 'c_resource', None) is not None):
return instance
else:
number_to_extend = index - instances_length + 1
instances.extend(None for _ in xrange(number_to_extend))
wand = self.image.wand
tmp_idx = library.MagickGetIteratorIndex(wand)
library.MagickSetIteratorIndex(wand, index)
image = library.GetImageFromMagickWand(wand)
exc = libmagick.AcquireExceptionInfo()
single_image = libmagick.CloneImages(image, binary(str(index)), exc)
libmagick.DestroyExceptionInfo(exc)
single_wand = library.NewMagickWandFromImage(single_image)
single_image = libmagick.DestroyImage(single_image)
library.MagickSetIteratorIndex(wand, tmp_idx)
instance = SingleImage(single_wand, self.image, image)
self.instances[index] = instance
return instance
if (instance is not None and
getattr(instance, 'c_resource', None) is not None):
return instance
else:
number_to_extend = index - instances_length + 1
instances.extend(None for _ in xrange(number_to_extend))
wand = self.image.wand
tmp_idx = library.MagickGetIteratorIndex(wand)
library.MagickSetIteratorIndex(wand, index)
image = library.GetImageFromMagickWand(wand)
exc = libmagick.AcquireExceptionInfo()
single_image = libmagick.CloneImages(image, binary(str(index)), exc)
libmagick.DestroyExceptionInfo(exc)
single_wand = library.NewMagickWandFromImage(single_image)
single_image = libmagick.DestroyImage(single_image)
library.MagickSetIteratorIndex(wand, tmp_idx)
instance = SingleImage(single_wand, self.image, image)
self.instances[index] = instance
return instance