Python Image Library: How to combine 4 images into a 2 x 2 grid?

前端 未结 5 992
情深已故
情深已故 2020-12-08 14:38

I have 4 directories with images for an animation. I would like to take the set of images and generate a single image with the 4 images arranged into a 2x2 grid for each fr

5条回答
  •  再見小時候
    2020-12-08 15:22

    Read the error message:

    AttributeError: 'NoneType' object has no attribute 'paste'
    

    This means you tried to call .paste on something that was of type NoneType, i.e. on the None object.

    Image.paste returns None. You can't "chain" together calls like that except when the functions are specifically designed to support it, and Image.paste is not. (Support for this sort of thing is accomplished by having the function return self. You get an error that talks about NoneType because the function is written not to return anything, and everything in Python returns None by default if nothing else is returned explicitly.) This is considered Pythonic: methods either return a new value, or modify self and return None. Thus, so-called "fluent interfaces" are not used when the functions have side effects - Pythonistas consider that harmful. Returning None is a warning that the function has side effects. :)

    Just do four separate .paste calls.

提交回复
热议问题