def test_jpeg_with_orientation_8(self): with open('tests/images/orientation/landscape_8.jpg', 'rb') as f: image = WandImage.open(JPEGImageFile(f)) image = image.auto_orient() self.assert_orientation_landscape_image_is_correct(image)
def test_resize_animated_gif(self): with open('tests/images/newtons_cradle.gif', 'rb') as f: image = WandImage.open(GIFImageFile(f)) resized_image = image.resize((100, 75)) self.assertTrue(resized_image.has_animation())
def test_jpeg_with_orientation_5(self): with open('tests/images/orientation/landscape_5.jpg', 'rb') as f: image = WandImage.open(JPEGImageFile(f)) image = image.auto_orient() self.assert_orientation_landscape_image_is_correct(image)
def test_animated_gif(self): with open('tests/images/newtons_cradle.gif', 'rb') as f: image = WandImage.open(GIFImageFile(f)) self.assertTrue(image.has_animation()) self.assertEqual(image.get_frame_count(), 34)
def test_jpeg_with_orientation_7(self): with open("tests/images/orientation/landscape_7.jpg", "rb") as f: image = WandImage.open(JPEGImageFile(f)) image = image.auto_orient() self.assert_orientation_landscape_image_is_correct(image)
def test_transparent_gif(self): with open('tests/images/transparent.gif', 'rb') as f: image = WandImage.open(GIFImageFile(f)) self.assertTrue(image.has_alpha()) self.assertFalse(image.has_animation()) # Check that the alpha of pixel 1,1 is 0 self.assertEqual(image.image[1][1].alpha, 0)
def test_resize_transparent_gif(self): with open('tests/images/transparent.gif', 'rb') as f: image = WandImage.open(GIFImageFile(f)) resized_image = image.resize((100, 75)) self.assertTrue(resized_image.has_alpha()) self.assertFalse(resized_image.has_animation()) # Check that the alpha of pixel 1,1 is 0 self.assertAlmostEqual(resized_image.image[1][1].alpha, 0, places=6)
def test_open_webp_lossless(self): original_image = self.image.image lossless_file = self.image.save_as_webp(io.BytesIO(), lossless=True) lossless_image = WandImage.open(lossless_file).image identically = True for x in range(original_image.width): for y in range(original_image.height): original_pixel = original_image[x, y] # don't compare fully transparent pixels if original_pixel.alpha == 0.0: continue if original_pixel != lossless_image[x, y]: identically = False break self.assertTrue(identically)
def setUp(self): with open('tests/images/transparent.png', 'rb') as f: self.image = WandImage.open(PNGImageFile(f))
def test_animated_gif(self): with open('tests/images/newtons_cradle.gif', 'rb') as f: image = WandImage.open(GIFImageFile(f)) self.assertTrue(image.has_animation())
import unittest import io import imghdr from wand.color import Color from PIL import Image as PILImage from willow.image import JPEGImageFile, PNGImageFile, GIFImageFile, WebPImageFile from willow.plugins.wand import _wand_image, WandImage, UnsupportedRotation no_webp_support = not WandImage.is_format_supported("WEBP") class TestWandOperations(unittest.TestCase): def setUp(self): with open('tests/images/transparent.png', 'rb') as f: self.image = WandImage.open(PNGImageFile(f)) def test_get_size(self): width, height = self.image.get_size() self.assertEqual(width, 200) self.assertEqual(height, 150) def test_resize(self): resized_image = self.image.resize((100, 75)) self.assertEqual(resized_image.get_size(), (100, 75)) def test_crop(self): cropped_image = self.image.crop((10, 10, 100, 100))
def test_open_webp_w_alpha(self): with open('tests/images/tux_w_alpha.webp', 'rb') as f: image = WandImage.open(WebPImageFile(f)) self.assertTrue(image.has_alpha()) self.assertFalse(image.has_animation())
def setUp(self): with open("tests/images/transparent.png", "rb") as f: self.image = WandImage.open(PNGImageFile(f))