from PIL import Image import io class ImageShrink: """Shrinks a given image (bytearray) to a given resolution (width, height)""" resolution = (480, 800) def __init__(self) -> None: pass def convert(self, image: bytearray) -> Image: # load image from bytearray image = Image.open(io.BytesIO(image)) image.show() image = self.shrink(image) image.show() image = self.convert_to_black_and_white(image) image.show() def shrink(self, image: Image) -> Image: """"Shrinks a given image (bytearray) to a given resolution (width, height)""" image.thumbnail(self.resolution) return image def convert_to_black_and_white(self, image: Image) -> Image: # img = Image.open(image) image = image.convert("L") return image