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

Python object not recognized as JPG despite previous manipulations

I am writing a program that pastes one jpeg onto another, however one of my functions stops recognizing an object as a jpeg file for unknown reasons.

My output is

"inside_select_letter_to_paste, letter to paste is a <class ‘NoneType’>.

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

and then

AttributeError: ‘NoneType’ object has no attribute ‘save’

Why is letter_to_paste not being recognized as a JPEG object despite the lines to open it and resize it as a thumbail working properly?

Thanks.

def select_letter_to_paste():

    letter_to_paste = Image.open(f'{letter_folder}\TEST-A.jpg')
    letter_to_paste = letter_to_paste.thumbnail((100,100))
    print(f'inside select_letter_to_paste, letter_to_paste is a {type(letter_to_paste)}.')
    letter_to_paste.save('test_letter.jpg')

  return letter_to_paste

>Solution :

Image.thumbnail modifies the image in-place and returns None.

The line

letter_to_paste = letter_to_paste.thumbnail((100,100))

is assigning None to letter_to_paste. Change it to

letter_to_paste.thumbnail((100,100))
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