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 Not Saved Properly jkreski 25 454 Mar-24-2026, 04:01 PM
Last Post: deanhystad
  image processing with opencv-python and Tesseract OCR marchellopl 4 157 Feb-15-2026, 12:27 AM
Last Post: Pedroski55
  why is the image not showing sarbogast 2 681 Nov-12-2025, 07:26 PM
Last Post: deanhystad
  please help with image resizing and image transparency ! magnus28 6 2,355 Jul-28-2025, 12:46 AM
Last Post: Pedroski55
  image does not show with pillow Mohamad_afeff_nasser 5 3,906 Apr-13-2025, 07:53 PM
Last Post: snippsat
  Placing image button on top of background image Sintek 1 1,187 Mar-02-2025, 05:36 PM
Last Post: Sintek
  Problem When using canny edge detection,black image returned rickyw2777 1 1,072 Feb-17-2025, 03:22 AM
Last Post: rickyw2777
  Why it gives me a black image and libpng warning: iCCP rickyw2777 1 1,137 Feb-16-2025, 08:26 PM
Last Post: rickyw2777
  QR code creation with image Raja31 1 4,794 Jan-15-2025, 11:17 AM
Last Post: Larz60+
Photo image generation with text style Belialhun 0 1,268 Oct-08-2024, 01:53 PM
Last Post: Belialhun

Forum Jump:

User Panel Messages

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