diff options
author | Erik Johnston <erik@matrix.org> | 2017-10-13 11:23:53 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2017-10-13 11:23:53 +0100 |
commit | 505371414f6ba9aeaa95eb8d34f7893c4cc2b07e (patch) | |
tree | 8856e14115964bcc3f133a3118eb9d8a723c8c8e /synapse/rest/media/v1/thumbnailer.py | |
parent | Fix typo (diff) | |
download | synapse-505371414f6ba9aeaa95eb8d34f7893c4cc2b07e.tar.xz |
Fix up thumbnailing function
Diffstat (limited to 'synapse/rest/media/v1/thumbnailer.py')
-rw-r--r-- | synapse/rest/media/v1/thumbnailer.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/synapse/rest/media/v1/thumbnailer.py b/synapse/rest/media/v1/thumbnailer.py index e1ee535b9a..09650bd527 100644 --- a/synapse/rest/media/v1/thumbnailer.py +++ b/synapse/rest/media/v1/thumbnailer.py @@ -54,7 +54,7 @@ class Thumbnailer(object): """Rescales the image to the given dimensions. Returns: - BytesIO: the bytes of the encoded image ready to be written to disk + ImageIO: the bytes of the encoded image ready to be written to disk """ scaled = self.image.resize((width, height), Image.ANTIALIAS) return self._encode_image(scaled, output_type) @@ -71,7 +71,7 @@ class Thumbnailer(object): max_height: The larget possible height. Returns: - BytesIO: the bytes of the encoded image ready to be written to disk + ImageIO: the bytes of the encoded image ready to be written to disk """ if width * self.height > height * self.width: scaled_height = (width * self.height) // self.width @@ -92,6 +92,13 @@ class Thumbnailer(object): return self._encode_image(cropped, output_type) def _encode_image(self, output_image, output_type): - output_bytes_io = BytesIO() + output_bytes_io = ImageIO(output_image.size) output_image.save(output_bytes_io, self.FORMATS[output_type], quality=80) + output_image.close() return output_bytes_io + + +class ImageIO(BytesIO): + def __init__(self, dimensions): + super(ImageIO, self).__init__() + self.dimensions = dimensions |