TypeError when trying to export JPEG

I am trying to export modified JPEG images of this image using the following code (the download part is omitted since this works fine):

basewidth = 400 # user-defined variable wpercent = (basewidth/float(img.size[0])) hsize = int((float(img.size[1])*float(wpercent))) img = img.resize((basewidth,hsize), Image.ANTIALIAS) theitemishere = "/home/myusername/public_html/resizer/" + filename img.save(theitemishere + extension, extension_caps) 

However, I get the following error when the time comes to save a new image (here's the trace):

  File "/home/myusername/public_html/cgi-bin/PIL/Image.py", line 1467, in save save_handler(self, fp, filename) File "/home/myusername/public_html/cgi-bin/PIL/JpegImagePlugin.py", line 557, in _save ImageFile._save(im, fp, [("jpeg", (0,0)+im.size, 0, rawmode)]) File "/home/myusername/public_html/cgi-bin/PIL/ImageFile.py", line 466, in _save e = Image._getencoder(im.mode, e, a, im.encoderconfig) File "/home/myusername/public_html/cgi-bin/PIL/Image.py", line 395, in _getencoder return encoder(mode, *args + extra) TypeError: function takes at most 11 arguments (13 given) 

Any thoughts on why this is happening?

FWIW, I cannot install the PIL module on the server, so I have it as a cgi-bin subdirectory.

+1
source share
2 answers

I had the same problem and it was resolved. By writing this solution, because I felt that the above answer is not descriptive enough for those who have the same problem and are looking for solutions.

I had this problem because I had PIL n Pillow installed. Therefore, I had to remove one of them. This solved the problem.

Thanks.

+7
source

You can skip everything and start by loading the image and save it immediately with:

 img.save("/home/myusername/public_html/resizer/file.jpg", format="JPEG") 

and see what happens. if it works, then add more details, resizing and other materials.

ah, and do not forget to check write permissions in the folder where you save, since the web server usually works under a different username.

+1
source

Source: https://habr.com/ru/post/1489526/


All Articles