26 lines
787 B
Python
26 lines
787 B
Python
from PIL import Image
|
|
|
|
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) -> bytearray:
|
|
image = self.shrink(image)
|
|
image = self.convert_to_black_and_white(image)
|
|
image.show()
|
|
|
|
|
|
def shrink(self, image: bytearray) -> bytearray:
|
|
""""Shrinks a given image (bytearray) to a given resolution (width, height)"""
|
|
img = Image.frombytes()
|
|
img = Image.open(image)
|
|
img.thumbnail(self.resolution)
|
|
return img
|
|
|
|
def convert_to_black_and_white(self, image: bytearray) -> bytearray:
|
|
img = Image.open(image)
|
|
img = img.convert("L")
|
|
return img |