Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is the type hint of a function that returns an image?

I have a function that takes 3 arguments and returns an image, I want to know that is the python type hint that the function returns.

Here is my function:

from PIL import Image

def modify_image(img_path: str, width: int, height: int) -> "what here?":
    """Read and return a resized image"""
    image = Image.open(img_path)
    modified_image = image.resize((width, height))

    return modified_image

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

According to the Pillow documentation, both Image.open() and Image.resize return Pillow Image objects, so your function should look something like

from PIL import Image

def modify_image(img_path: str, width: int, height: int) -> Image:
    ...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading