rotating only a part of the image in python

2019-07-29 17:17发布

Sorry, I'm a complete noob when it comes to coding. I've got a question for rotating only a portion of the image using Python. I already have PIL imported and the rotate function working but I can't make it rotate only a portion of the image. Any help would be greatly appreciated.

from PIL import Image
import _imaging
import sys

myImage = Image.open("img.gif")

for x in range():
    for y in range():
        myImage.rotate(90).show()

I have something like that

1条回答
地球回转人心会变
2楼-- · 2019-07-29 18:22

i would propose the following solution:

inlay = img.crop((x1,y1,x2,y2)).rotate(90)
img.paste(inlay, (x1,y1,x2,y2))

x1,y1 is the left upper corner and x2,y2 the lower right corner of the inlay/sub-image.

img = myImage from your example

查看更多
登录 后发表回答