1

I'm trying to export resized JPEGs of a given image using the following code (the downloading part is omitted, since that 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 it comes time to save the new image (here's the traceback):

  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'm unable to install the PIL module on the server, which is why I have it as a subdirectory of cgi-bin.

1
  • Full source code can be found in this gist Commented Mar 24, 2013 at 23:27

2 Answers 2

7

I had the same problem and solved it. Writing this solution as I felt that the above answer is not descriptive enough for anyone else having the same problem and looking for solutions

I had this problem because I had both PIL n Pillow installed. So had to uninstall one of them. That solved the problem.

Thanks.

Sign up to request clarification or add additional context in comments.

1 Comment

I faced a very similar problem, but instead of uninstalling one of the libraries, I just changed the import statement. Have a look at my question & solution at stackoverflow.com/questions/17451711/…
1

You might want to skip everything and start from loading image and immediately saving it 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 stuff.

ah, and don't forget to check write permissions on the folder where you save, because web-server usually runs under different user name.

5 Comments

I'm getting the same basic error: 11 args, 13 given...double checked the permissions — they're not the issue. In fact, the file itself gets created (albeit with a size of 0 bytes)...so it looks like the issue happens somewhere in the midst of it being saved. Thoughts?
I'd try to install the exact same version of PIL on the development machine, but properly (not in cgi-bin) and check if it runs well. If it works, you need to reinstall things on the server, if it does not, you need a different version of PIL.
Works perfectly on the development machine; looks like you were right in that there's something funky going on with the server.
@tehsockz I m having the exact problem. Can you help by letting me know how you solved it. Coz from the previous comments it looks that it didnt work and than suddenly you write success.
@SaranshMohapatra Server issues; I restarted it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.