Python Forum
PIL Image / python-resize-image AttributeError
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PIL Image / python-resize-image AttributeError
#1
Hi, I am getting an Attribute Error when using the PIL mage module. Not sure what the cause is as the no attribute of 'upper' is not written in the code, and when searching for similar errors, the missing attribute seems to be written in the code.

for file in glob.glob("*.png"):
  img = Image.open(file)
  rec = resizeimage.resize_crop(img, [200, 100])
  filename = "rec_"+ file 
  img.save(output + filename, rec)
Error:
AttributeError Traceback (most recent call last) <ipython-input-23-f08ed3820260> in <module>() 3 rec = resizeimage.resize_crop(img, [200, 100]) 4 filename = "rec_"+ file ----> 5 img.save(output + filename, rec) /usr/local/lib/python3.6/dist-packages/PIL/Image.py in save(self, fp, format, **params) 2084 raise ValueError("unknown file extension: {}".format(ext)) 2085 -> 2086 if format.upper() not in SAVE: 2087 init() 2088 if save_all: AttributeError: 'Image' object has no attribute 'upper'
What is the cause and solution to this error? Would be much appreciated.
Reply
#2
rec parameter should specify the format of an image, e.g. "png", "jpeg" etc. In your case, you passed an Image-instance (rec is an Image instance). Try, e.g. img.save(output+filename, 'png')
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  image does not show with pillow Mohamad_afeff_nasser 5 287 Apr-13-2025, 07:53 PM
Last Post: snippsat
  Placing image button on top of background image Sintek 1 475 Mar-02-2025, 05:36 PM
Last Post: Sintek
  Problem When using canny edge detection,black image returned rickyw2777 1 424 Feb-17-2025, 03:22 AM
Last Post: rickyw2777
  Why it gives me a black image and libpng warning: iCCP rickyw2777 1 427 Feb-16-2025, 08:26 PM
Last Post: rickyw2777
  QR code creation with image Raja31 1 712 Jan-15-2025, 11:17 AM
Last Post: Larz60+
Photo image generation with text style Belialhun 0 641 Oct-08-2024, 01:53 PM
Last Post: Belialhun
  Product Image Download Help Required pythonustasi 5 1,302 Jul-21-2024, 08:12 PM
Last Post: snippsat
  tkinter photo image problem jacksfrustration 5 3,347 Jun-27-2024, 12:06 AM
Last Post: AdamHensley
Photo image error pyc0de 2 1,757 Mar-23-2024, 06:20 PM
Last Post: pyc0de
  Using OpenCV and image path is invalid AudunNilsen 5 1,912 Mar-18-2024, 05:28 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020