dawen
dawen

Reputation: 163

how to paste a rotate image without cropping sides

this is the original back image this is the original front image this is my code:

from PIL import Image
front=Image.open('/users/apple/Desktop/TMP.jpeg')
back=Image.open('/Users/apple/Desktop/原始图片/084.jpeg')
front=front.rotate(100,expand=True)
back.paste(front,(100,100))
back

this is what i get. i want a clean paste without cropping sides. can somebody help me ,thanks.

Upvotes: 4

Views: 6589

Answers (1)

Mark Ransom
Mark Ransom

Reputation: 308520

You need to generate a mask that you can pass to paste to exclude the new black edges.

mask = Image.new('L', front.size, 255)
front = front.rotate(100, expand=True)
mask = mask.rotate(100, expand=True)
back.paste(front, (100,100), mask)

Result

Upvotes: 8

Related Questions