Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def error_image(msg, width=420, height=600):
"""Creates an error frontpage"""
width, height = int(width), int(height)
img = WandImage(width=width, height=height)
with Drawing() as draw:
draw.text_alignment = 'center'
draw.text(img.width // 2, img.height // 3, msg)
draw(img)
background = WandImage(
width=img.width,
height=img.height,
background=Color('white'),
)
background.format = 'jpeg'
background.composite(img, 0, 0)
return background
def rotate():
"""Rotates an image."""
with Image(filename=asset('rotatetest.gif')) as img:
assert 150 == img.width
assert 100 == img.height
with img.clone() as cloned:
cloned.rotate(360)
assert img.size == cloned.size
with Color('black') as black:
assert black == cloned[0, 50] == cloned[74, 50]
assert black == cloned[0, 99] == cloned[74, 99]
with Color('white') as white:
assert white == cloned[75, 50] == cloned[75, 99]
with img.clone() as cloned:
cloned.rotate(90)
assert 100 == cloned.width
assert 150 == cloned.height
with Color('black') as black:
with Color('white') as white:
@tests.test
def setitem():
with Image(filename=asset('apple.ico')) as imga:
with Image(filename=asset('google.ico')) as imgg:
imga.sequence[2] = imgg
assert len(imga.sequence) == 4
assert imga.sequence[2].size == (16, 16)
expire(imga)
assert imga.sequence[2].size == (16, 16)
@tests.test
def extend_offset():
with Image(filename=asset('apple.ico')) as a:
instances = list(a.sequence)
with Image(filename=asset('github.ico')) as b:
a.sequence.extend(list(b.sequence)[::-1], 2)
instances[2:2] = list(b.sequence)[::-1]
assert list(a.sequence) == instances
expire(a)
assert list(a.sequence) == instances
assert len(a.sequence) == 6
def equals():
"""Equality test."""
assert Color('#fff') == Color('#ffffff') == Color('white')
assert Color('#000') == Color('#000000') == Color('black')
assert Color('rgba(0, 0, 0, 0)') == Color('rgba(0, 0, 0, 0)')
assert Color('rgba(0, 0, 0, 0)') == Color('rgba(1, 1, 1, 0)')
def set_get_text_under_color(wand):
with Color('#333333') as black:
wand.text_under_color = black
assert wand.text_under_color == Color('#333333')
def not_equals():
"""Equality test."""
assert Color('#000') != Color('#fff')
assert Color('rgba(0, 0, 0, 0)') != Color('rgba(0, 0, 0, 1)')
assert Color('rgba(0, 0, 0, 1)') != Color('rgba(1, 1, 1, 1)')
def equals():
"""Equality test."""
assert Color('#fff') == Color('#ffffff') == Color('white')
assert Color('#000') == Color('#000000') == Color('black')
assert Color('rgba(0, 0, 0, 0)') == Color('rgba(0, 0, 0, 0)')
assert Color('rgba(0, 0, 0, 0)') == Color('rgba(1, 1, 1, 0)')
def test_fit_liquid(self):
pipeline = [giraffe.ImageOp('liquid', {'width': 100, 'height': 100})]
try:
img = giraffe.process_image(self.image, pipeline)
except MissingDelegateError:
pytest.skip("ImageMagick doesn't have Liquid Rescale support compiled in")
self.assertEqual(img.size, (100, 100))
def liquid_rescale():
def assert_equal_except_alpha(a, b):
with a:
with b:
assert (a.red == b.red and
a.green == b.green and
a.blue == b.blue)
with Image(filename=asset('beach.jpg')) as orig:
with orig.clone() as img:
try:
img.liquid_rescale(600, 600)
except MissingDelegateError:
warnings.warn('skip liquid_rescale test; has no LQR delegate')
else:
assert img.size == (600, 600)
for x in 0, -1:
for y in 0, -1:
assert_equal_except_alpha(img[x, y], img[x, y])