Specify image filling color when rotating in python with PIL and setting expand argument to true

后端 未结 3 519
花落未央
花落未央 2020-12-10 11:28

I\'m trying to rotate an image in Python using PIL and having the expand argument to true. It seems that when the background of my image is black, the resulting image saved

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-10 11:36

    There is a parameter fillcolor in a rotate method to specify color which will be use for expanded area:

    white = (255,255,255)
    pil_image.rotate(angle, PIL.Image.NEAREST, expand = 1, fillcolor = white)
    

    https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.rotate

提交回复
热议问题