Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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()
else:
font_metrics_f = library.MagickQueryFontMetrics
if isinstance(text, text_type):
if self.text_encoding:
text = text.encode(self.text_encoding)
else:
text = binary(text)
result = font_metrics_f(image.wand, self.resource, text)
if not result: # pragma: no cover
# Error on drawing context
self.raise_exception()
# Or error on image canvas
image.raise_exception()
# Generate a generic error if ImageMagick couldn't emit one.
raise ValueError('Unable to render text with current font.')
args = [result[i] for i in xrange(13)]
library.MagickRelinquishMemory(result)
return FontMetrics(*args)
def __iter__(self):
if self.counts is None:
pixels = self.pixels
string = library.PixelGetColorAsString
return (Color(string(pixels[i]).value)
for i in xrange(self.size.value))
return iter(Color(string=c) for c in self.counts)
length = len(self)
if slice_.start is None:
start = 0
elif slice_.start < 0:
start = length + slice_.start
else:
start = slice_.start
start = min(length, start)
if slice_.stop is None:
stop = 0
elif slice_.stop < 0:
stop = length + slice_.stop
else:
stop = slice_.stop
stop = min(length, stop or length)
return xrange(start, stop) if as_range else slice(start, stop, None)
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()
def __getitem__(self, index):
if isinstance(index, slice):
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()
def __next__(self, x=None):
if self.cursor >= self.height:
self.destroy()
raise StopIteration()
self.cursor += 1
width = ctypes.c_size_t()
pixels = library.PixelGetNextIteratorRow(self.resource,
ctypes.byref(width))
get_color = library.PixelGetMagickColor
struct_size = ctypes.sizeof(MagickPixelPacket)
if x is None:
r_pixels = [None] * width.value
for x in xrange(width.value):
pc = pixels[x]
packet_buffer = ctypes.create_string_buffer(struct_size)
get_color(pc, packet_buffer)
r_pixels[x] = Color(raw=packet_buffer)
return r_pixels
packet_buffer = ctypes.create_string_buffer(struct_size)
get_color(pixels[x], packet_buffer)
return Color(raw=packet_buffer)
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:
self.raise_exception()
self.wand = new_wand