Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
raise TypeError("crop must be a string, not " + repr(crop))
if not isinstance(resize, string_type):
raise TypeError("resize must be a string, not " + repr(resize))
# 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:
elif not isinstance(start_width, numbers.Integral):
raise TypeError('start_width must be an integer, not ' + repr(height))
elif not isinstance(start_height, numbers.Integral):
raise TypeError('start_height must be an integer, not ' + repr(height))
elif not isinstance(delta_x, numbers.Real):
raise TypeError('delta_x must be a float, not ' + repr(delta_x))
elif not isinstance(rigidity, numbers.Real):
raise TypeError('rigidity must be a float, not ' + repr(rigidity))
if self.animation:
# scale each frame in the image, linearly scaling the rescale amount per frame
# if start_width/height != rescale_width/height
# coalesce outputs each frame as the viewer sees it instead of in its optimized form, as rescaling a
# non-coalesced image results in artifacts on the optimized frames
self.wand = library.MagickCoalesceImages(self.wand)
num_frames = len(self.sequence)
rescale_width_step = float(start_width - width) / num_frames
rescale_height_step = float(start_height - height) / num_frames
def _rescale_frame(index):
rescale_width = int(start_width - rescale_width_step * index)
rescale_height = int(start_height - rescale_height_step * index)
rescaled_frame = ContentAwareImage(image=self.sequence[index])
rescaled_frame.content_aware_scale(rescale_width, rescale_height, start_width, start_height,
units_percent=units_percent, use_slow_scaling=use_slow_scaling,
delta_x=delta_x, rigidity=rigidity)
return rescaled_frame
# process gifs concurrently for maximum speed
raise TypeError('blur must be numbers.Real , not ' + repr(blur))
elif not isinstance(filter, (string_type, numbers.Integral)):
raise TypeError('filter must be one string defined in wand.image.'
'FILTER_TYPES or an integer, not ' + repr(filter))
if isinstance(filter, string_type):
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()
if height is None:
height = self.height
if not isinstance(width, numbers.Integral):
raise TypeError('width must be a natural number, not ' +
repr(width))
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()
The ``reset_coords`` parameter.
.. versionadded:: 0.1.8
"""
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()
top = abs_(top, self.height, 0)
if width is None:
right = abs_(right, self.width)
width = right - left
if height is None:
bottom = abs_(bottom, self.height)
height = bottom - top
if width < 1:
raise ValueError('image width cannot be zero')
elif height < 1:
raise ValueError('image width cannot be zero')
elif (left == top == 0 and width == self.width and
height == self.height):
return
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(0, n + 1):
library.MagickSetIteratorIndex(self.wand, i)
library.MagickCropImage(self.wand, width, height, left, top)
if reset_coords:
library.MagickResetImagePage(self.wand, None)
else:
library.MagickCropImage(self.wand, width, height, left, top)
self.raise_exception()
if reset_coords:
self.reset_coords()
def open_image(self, input_file):
image = Image(file=input_file)
image.wand = library.MagickCoalesceImages(image.wand)
return image