Why is my imageops.fit() parameters throwing position argument follows keyword argument syntax error?

Question:

I would like to take the argument provided in the command line first and crop/change it to the values I inputted in as the parameters but I get the error:

SyntaxError: positional argument follows keyword argument

I thought I used the syntax correctly as per its read doc: https://pillow.readthedocs.io/en/stable/reference/ImageOps.html#PIL.ImageOps.fit

Here is code:

import sys
from PIL import Image, ImageOps

with Image.open(sys.argv[1]) as im:
        new_image = ImageOps.fit(im, size = im.width, im.height, method = Image.BICUBIC, bleed = 0.0, centering = (0.5, 0.5))
Asked By: Dave

||

Answers:

The problem is the last line, you can’t have

somefunc(123, size=456, 'hello', ...)

Once you have a keyword argument (size=), all subsequent argument must also be keyword arguments. Perhaps you forgot to put the width and height into a tuple:

new_image = ImageOps.fit(im, size = (im.width, im.height), method = Image.BICUBIC, bleed = 0.0, centering = (0.5, 0.5)) #brackets added
Answered By: ReasonMeThis