How to paste an image onto a larger image using Pillow?

前端 未结 2 818
一生所求
一生所求 2020-12-14 18:53

I\'ve got a fairly simple code file:

from PIL import Image
til = Image.new(\"RGB\",(50,50))
im = Image.open(\"tile.png\") #25x25
til.paste(im)
til.paste(im,(         


        
2条回答
  •  忘掉有多难
    2020-12-14 19:10

    The problem is in the first pasting - according to the PIL documentation (http://effbot.org/imagingbook/image.htm), if no "box" argument is passed, images' sizes must match.

    EDIT: I actually misunderstood the documentation, you are right, it's not there. But from what I tried here, it seems like passing no second argument, sizes must match. If you want to keep the second image's size and place it in the upper-left corner of the first image, just do:

    ...
    til.paste(im,(0,0))
    ...
    

提交回复
热议问题