def setUp(self):
        """Run before the test."""
        # Create an image in memory
        from PIL import Image
        from flask_iiif.api import MultimediaImage
        tmp_file = BytesIO()
        # create a new image
        image = Image.new("RGBA", (1280, 1024), (255, 0, 0, 0))
        image.save(tmp_file, 'png')

        # create a new gif image
        self.image_gif = MultimediaImage(
            create_gif_from_frames([
                Image.new("RGB", (1280, 1024), color)
                for color in ['blue', 'yellow', 'red', 'black', 'white']
            ]))

        # Initialize it for our object and create and instance for
        # each test
        tmp_file.seek(0)
        self.image_resize = MultimediaImage.from_string(tmp_file)
        tmp_file.seek(0)
        self.image_crop = MultimediaImage.from_string(tmp_file)
        tmp_file.seek(0)
        self.image_rotate = MultimediaImage.from_string(tmp_file)
        tmp_file.seek(0)
        self.image_errors = MultimediaImage.from_string(tmp_file)
        tmp_file.seek(0)
        self.image_convert = MultimediaImage.from_string(tmp_file)
        tmp_file.seek(0)
        self.image_save = MultimediaImage.from_string(tmp_file)

        # NOT RGBA
        tmp_file = BytesIO()
        # create a new image
        image = Image.new("RGB", (1280, 1024), (255, 0, 0, 0))
        image.save(tmp_file, 'jpeg')
        tmp_file.seek(0)
        self.image_not_rgba = MultimediaImage.from_string(tmp_file)

        # Image in P Mode
        tmp_file = BytesIO()
        image = Image.new("P", (1280, 1024))
        image.save(tmp_file, 'gif')
        tmp_file.seek(0)
        self.image_p_mode = MultimediaImage.from_string(tmp_file)

        # TIFF Image
        tmp_file = BytesIO()
        image = Image.new("RGBA", (1280, 1024), (255, 0, 0, 0))
        image.save(tmp_file, 'tiff')
        tmp_file.seek(0)
        self.image_tiff = MultimediaImage.from_string(tmp_file)
    def setUp(self, width=1280, height=1024):
        """Run before the test."""
        # Create an image in memory

        tmp_file = BytesIO()
        # create a new image
        image = Image.new("RGBA", (width, height), (255, 0, 0, 0))
        image.save(tmp_file, 'png')

        # create a new gif image
        self.image_gif = MultimediaImage(create_gif_from_frames([
            Image.new("RGB", (width, height), color)
            for color in ['blue', 'yellow', 'red', 'black', 'white']
        ]))
        self.width, self.height = width, height
        # Initialize it for our object and create and instance for
        # each test
        tmp_file.seek(0)
        self.image_resize = MultimediaImage.from_string(tmp_file)
        tmp_file.seek(0)
        self.image_crop = MultimediaImage.from_string(tmp_file)
        tmp_file.seek(0)
        self.image_rotate = MultimediaImage.from_string(tmp_file)
        tmp_file.seek(0)
        self.image_errors = MultimediaImage.from_string(tmp_file)
        tmp_file.seek(0)
        self.image_convert = MultimediaImage.from_string(tmp_file)
        tmp_file.seek(0)
        self.image_save = MultimediaImage.from_string(tmp_file)

        # NOT RGBA
        tmp_file = BytesIO()
        # create a new image
        image = Image.new("RGB", (width, height), (255, 0, 0, 0))
        image.save(tmp_file, 'jpeg')
        tmp_file.seek(0)
        self.image_not_rgba = MultimediaImage.from_string(tmp_file)

        # Image in P Mode
        tmp_file = BytesIO()
        image = Image.new("P", (width, height))
        image.save(tmp_file, 'gif')
        tmp_file.seek(0)
        self.image_p_mode = MultimediaImage.from_string(tmp_file)

        # TIFF Image
        tmp_file = BytesIO()
        image = Image.new("RGBA", (width, height), (255, 0, 0, 0))
        image.save(tmp_file, 'tiff')
        tmp_file.seek(0)
        self.image_tiff = MultimediaImage.from_string(tmp_file)
    def setUp(self):
        """Run before the test."""
        # Create an image in memory
        from PIL import Image
        from flask_iiif.api import MultimediaImage
        tmp_file = BytesIO()
        # create a new image
        image = Image.new("RGBA", (1280, 1024), (255, 0, 0, 0))
        image.save(tmp_file, 'png')

        # Initialize it for our object and create and instance for
        # each test
        tmp_file.seek(0)
        self.image_resize = MultimediaImage.from_string(tmp_file)
        tmp_file.seek(0)
        self.image_crop = MultimediaImage.from_string(tmp_file)
        tmp_file.seek(0)
        self.image_rotate = MultimediaImage.from_string(tmp_file)
        tmp_file.seek(0)
        self.image_errors = MultimediaImage.from_string(tmp_file)
        tmp_file.seek(0)
        self.image_convert = MultimediaImage.from_string(tmp_file)
        tmp_file.seek(0)
        self.image_save = MultimediaImage.from_string(tmp_file)

        # NOT RGBA
        tmp_file = BytesIO()
        # create a new image
        image = Image.new("RGB", (1280, 1024), (255, 0, 0, 0))
        image.save(tmp_file, 'jpeg')
        tmp_file.seek(0)
        self.image_not_rgba = MultimediaImage.from_string(tmp_file)
예제 #4
0
    def setUp(self):
        """Run before the test."""
        # Create an image in memory
        from PIL import Image
        from flask_iiif.api import MultimediaImage
        tmp_file = BytesIO()
        # create a new image
        image = Image.new("RGBA", (1280, 1024), (255, 0, 0, 0))
        image.save(tmp_file, 'png')

        # Initialize it for our object and create and instance for
        # each test
        tmp_file.seek(0)
        self.image_resize = MultimediaImage.from_string(tmp_file)
        tmp_file.seek(0)
        self.image_crop = MultimediaImage.from_string(tmp_file)
        tmp_file.seek(0)
        self.image_rotate = MultimediaImage.from_string(tmp_file)
        tmp_file.seek(0)
        self.image_errors = MultimediaImage.from_string(tmp_file)
        tmp_file.seek(0)
        self.image_convert = MultimediaImage.from_string(tmp_file)
        tmp_file.seek(0)
        self.image_save = MultimediaImage.from_string(tmp_file)

        # NOT RGBA
        tmp_file = BytesIO()
        # create a new image
        image = Image.new("RGB", (1280, 1024), (255, 0, 0, 0))
        image.save(tmp_file, 'jpeg')
        tmp_file.seek(0)
        self.image_not_rgba = MultimediaImage.from_string(tmp_file)
예제 #5
0
    def test_image_recreation(self):
        """Test the image recreation from cache."""
        from flask_iiif.api import MultimediaImage

        # Seek position
        self.image_file.seek(0)
        # Add the image to cache
        self.cache.set('image_2', self.image_file.getvalue())
        # Get image from cache
        image_string = self.cache.get('image_2')
        # Create a ByteIO object
        cached_image = BytesIO(image_string)
        # Seek object to the right position
        cached_image.seek(0)
        # Create an image object form the stored string
        image = MultimediaImage.from_string(cached_image)
        # Check if the image is still the same
        self.assertEqual(str(image.size()), str((1280, 1024)))